0

I have entity class in created using entity framework which is in my Domain project

    using System;
    using System.Collections.Generic;

    public partial class Test
    {
        public int Id { get; set; }
        public int ExamID { get; set; }
        public string TestName { get; set; }
        public string StartDescription { get; set; }
        public string EndDescription { get; set; }
      }

And In my MVC application I am creating one viewmodel which I use in my view

public class TestViewModel
{
   public Test Test { get; set; }
}

Now I want to make fields related to "StartDescription" and "EndDescription", for this is am trying to use TinyMCE.

Now the problem is "[AllowHtml]" attribute is in mvc but my real entity is in other project

I am following this tutorial. http://www.codeproject.com/Articles/674754/TinyMCE-and-ASP-NET-MVC-advanced-features

vaibhav shah
  • 4,939
  • 19
  • 58
  • 96

2 Answers2

1

Rather than your view model having an instance of Test it should contain the properties you wish to use in the view. You can then add the [AllowHtml] attribute to the properties in your view model without affecting your domain objects.

public class TestViewModel
{
    public int Id { get; set; }

    [AllowHtml]
    public string StartDescription { get; set; }
    [AllowHtml]
    public string EndDescription { get; set; }
}

In your controller you would then need to map the view model to your domain class.

petelids
  • 12,305
  • 3
  • 47
  • 57
  • there is no other way to do this ? – vaibhav shah Aug 01 '14 at 07:21
  • Because TestViewModel might also have instances of other entity classes also. – vaibhav shah Aug 01 '14 at 07:44
  • Are you using _all_ of the properties from the other domain objects? If not then I think that's even more reason to create a separate ViewModel. A good explanation can be found here - http://stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc – petelids Aug 01 '14 at 17:29
0

Old post but thought this might be relevant for someone else:

borrowing a sample code from petelids and modifying it.

public class TestViewModel
{
    public int Id { get; set; }

    [UIHint("tinymce_jquery_full"), AllowHtml]
    public string StartDescription { get; set; }
    [UIHint("tinymce_jquery_full"), AllowHtml]
    public string EndDescription { get; set; }
}

Providing the UIHint on the model object you can place your tinyMCE script code in a file saved in the Folder

~/Views/Shared/TemplateEditor

I do this using the TinyMCE4.MVC libraries - however mine is modified a bit for my own special workings that I have added.

Ken
  • 2,518
  • 2
  • 27
  • 35