【问题标题】:How to use TinyMCE with entity framework entities如何将 TinyMCE 与实体框架实体一起使用
【发布时间】:2014-09-23 23:58:41
【问题描述】:

我使用我的域项目中的实体框架创建了实体类

    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 应用程序中,我正在创建一个在我的视图中使用的视图模型

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

【问题讨论】:

    标签: c# asp.net-mvc entity-framework asp.net-mvc-4 tinymce


    【解决方案1】:

    而不是您的视图模型具有Test 的实例,它应该包含您希望在视图中使用的属性。然后,您可以将 [AllowHtml] 属性添加到视图模型中的属性,而不会影响您的域对象。

    public class TestViewModel
    {
        public int Id { get; set; }
    
        [AllowHtml]
        public string StartDescription { get; set; }
        [AllowHtml]
        public string EndDescription { get; set; }
    }
    

    在您的控制器中,您需要将视图模型映射到您的域类。

    【讨论】:

    • 没有其他办法吗?
    • 因为 TestViewModel 也可能有其他实体类的实例。
    • 您是否使用了其他域对象的 所有 属性?如果不是,那么我认为这更有理由创建一个单独的 ViewModel。可以在这里找到一个很好的解释 - stackoverflow.com/questions/11064316/what-is-viewmodel-in-mvc
    【解决方案2】:

    旧帖子,但认为这可能与其他人有关:

    从 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 脚本代码放在文件夹中保存的文件中

    ~/Views/Shared/TemplateEditor

    我使用 TinyMCE4.MVC 库执行此操作 - 但是我的库针对我添加的特殊工作做了一些修改。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-14
      • 2016-03-09
      • 1970-01-01
      相关资源
      最近更新 更多