EditorFor不处理不同dll中的类

时间:2013-08-07 07:30:44

标签: asp.net-mvc tinymce editorfor

我有两个项目的解决方案。

其中一个包含数据访问层类(DAL.dll),另一个是ASP.NET MVC项目。 ASP.NET MVC项目依赖于DAL.dll。 我想在ASP.NET MVC项目的模型类中使用DAL.dll类。

假设我在DAL.dll中有一个类,如下所示:

public class Test{

  public string Description{get;set;}

}

而且,在ASP.NET MVC项目中,我有一个使用Test.cs的模型类,如下所示:

public class ModelClass{

  Test CrudModel{get;set;}

  public string Description{get;set;} 

}

而且,在我看来(* .cshtml)我有以下代码:

@Html.EditorFor(model => model.CrudModel.Description, "tinymce_jquery_min")

在上面的代码中,@Html.EditorFor不呈现“tinymce_jquery_min”模板。

但是,当我使用以下代码时,@Html.EditorFor会渲染“tinymce_jquery_min”模板:

 @Html.EditorFor(model => model.Description, "tinymce_jquery_min")

为什么@Html.EditorFor只为ASP.NET MVC项目中的模型类中的属性呈现模板,而不为其他dll中的属性呈现模板?

更新

“tinymce_jquery_min”模板如下:

<script src="@Url.Content("~/Scripts/tinymce/jquery.tinymce.js")"      type="text/javascript"></script>

   <script type="text/javascript">
   $(document).ready(function () {
        setTimeout(loadTinyMCE, 500);
    });

  function loadTinyMCE() {
      $('#@ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)').tinymce({


              script_url: '@Url.Content("~/Scripts/tinymce/tiny_mce.js")',
              theme: "advanced",

              height: "300",
              width: "400",
              verify_html: false,

              theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                      theme_advanced_toolbar_location: "top",
              theme_advanced_toolbar_align: "left",
              theme_advanced_statusbar_location: "bottom",
              theme_advanced_resizing: false,


              convert_urls: false,


              template_external_list_url: "lists/template_list.js",
              external_link_list_url: "lists/link_list.js",
              external_image_list_url: "lists/image_list.js",
              media_external_list_url: "lists/media_list.js"

          });
  }





 </script>
        @Html.TextArea(string.Empty,  
          ViewData.TemplateInfo.FormattedModelValue  
       )

2 个答案:

答案 0 :(得分:0)

这是强烈输入部分视图的方法。定义模型(在这种情况下为string类型),并使用Html.TextAreaFor呈现TextArea:

@model string

<script src="@Url.Content("~/Scripts/tinymce/jquery.tinymce.js")" type="text/javascript"></script>

<script type="text/javascript">
   $(document).ready(function () {
      setTimeout(loadTinyMCE, 500);
   });

   function loadTinyMCE() {
      $('#@ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)').tinymce({


              script_url: '@Url.Content("~/Scripts/tinymce/tiny_mce.js")',
              theme: "advanced",

              height: "300",
              width: "400",
              verify_html: false,

              theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
                      theme_advanced_toolbar_location: "top",
              theme_advanced_toolbar_align: "left",
              theme_advanced_statusbar_location: "bottom",
              theme_advanced_resizing: false,


              convert_urls: false,


              template_external_list_url: "lists/template_list.js",
              external_link_list_url: "lists/link_list.js",
              external_image_list_url: "lists/image_list.js",
              media_external_list_url: "lists/media_list.js"

      });
   }
</script>

@Html.TextAreaFor(model => model)

答案 1 :(得分:0)

感谢ataravati 的帮助。 我的模板中似乎有一个错误。 我必须改变

   ViewData.TemplateInfo.GetFullHtmlFieldName

   ViewData.TemplateInfo.GetFullHtmlFieldId

因为ASP MVC在以下代码中为id属性和name属性创建了不同的值:

@Html.EditorFor(model => model.CrudModel.Description, "tinymce_jquery_min")

然后

  ViewData.TemplateInfo.GetFullHtmlFieldName

不起作用。