0

I have a solution with two projects.

One of them contains data access layer classes (DAL.dll), and the other one is an ASP.NET MVC project. The ASP.NET MVC project depends on DAL.dll. I want to use the DAL.dll classes in a model class in the ASP.NET MVC project.

Suppose that I have a class in DAL.dll as follows:

public class Test{

  public string Description{get;set;}

}

And, in the ASP.NET MVC project I have a model class that uses Test.cs as follows:

public class ModelClass{

  Test CrudModel{get;set;}

  public string Description{get;set;} 

}

And, in my view (*.cshtml) I have following code:

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

In the above code, @Html.EditorFor does not render "tinymce_jquery_min" template.

But, when I use the following code, @Html.EditorFor does render "tinymce_jquery_min" template:

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

Why @Html.EditorFor only renders template for properties those are in model class in the ASP.NET MVC project and not for properties in a different dll?

Updated

"tinymce_jquery_min" template is as follow :

<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  
       )
4

2 回答 2

0

这就是你如何使你的局部视图成为强类型的。定义模型(在本例中为字符串类型),并用于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)
于 2013-08-09T13:54:03.127 回答
0

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

   ViewData.TemplateInfo.GetFullHtmlFieldName

   ViewData.TemplateInfo.GetFullHtmlFieldId

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

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

然后

  ViewData.TemplateInfo.GetFullHtmlFieldName

不起作用。

于 2013-08-10T14:40:03.310 回答