我使用实体框架创建了实体类,该框架位于我的Domain项目
中 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; }
}
在我的MVC应用程序中,我创建了一个我在视图中使用的viewmodel
public class TestViewModel
{
public Test Test { get; set; }
}
现在我想创建与“StartDescription”和“EndDescription”相关的字段,因为这是我尝试使用TinyMCE。
现在问题是“[AllowHtml]”属性在mvc中,但我的真实实体在其他项目中
我正在学习本教程。 http://www.codeproject.com/Articles/674754/TinyMCE-and-ASP-NET-MVC-advanced-features
答案 0 :(得分:0)
而不是具有Test
实例的视图模型,它应该包含您希望在视图中使用的属性。然后,您可以将[AllowHtml]
属性添加到视图模型中的属性,同时影响您的域对象。
public class TestViewModel
{
public int Id { get; set; }
[AllowHtml]
public string StartDescription { get; set; }
[AllowHtml]
public string EndDescription { get; set; }
}
在控制器中,您需要将视图模型映射到域类。
答案 1 :(得分:0)
旧帖子,但认为这可能与其他人有关:
从petelids中借用示例代码并对其进行修改。
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; }
}
在模型对象上提供UIHint,您可以将tinyMCE脚本代码放置在Folder文件夹中保存的文件中
〜/ Views / Shared / TemplateEditor
我使用TinyMCE4.MVC库执行此操作-但是我为自己添加的特殊工作做了一些修改。