使用ASP.NET MVC v2 EditorFor和DisplayFor与IEnumerable <T>泛型类型

Dan*_*ite 33 asp.net-mvc

我有一个在我的模型中IList<Tag>命名的属性Tags.如何命名文件显示和编辑模板,要尊重它,当我打电话DisplayFor还是EditorFor?用法:

模型

class MyModel 
{
    IList<Tag> Tags { get; protected set; }
}
Run Code Online (Sandbox Code Playgroud)

视图

<%= Html.EditorFor(t => t.Tags) %>
Run Code Online (Sandbox Code Playgroud)

编辑 我知道我可以做到这一点,但它不是我想要做的.

<%= Html.EditorFor(t => t.Tags, "TagList") %>
Run Code Online (Sandbox Code Playgroud)

Dan*_*ann 31

使用属性[UIHint("Tags")]然后在DisplayTemplates文件夹中创建名为Tags.ascx的显示模板.

class MyModel 
{
    [UIHint("Tags")]
    IList<Tag> Tags { get; protected set; }
}
Run Code Online (Sandbox Code Playgroud)

并在文件Tags.ascx中

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IEnumerable<Tag>>" %>
<!-- put your Model code here -> 
Run Code Online (Sandbox Code Playgroud)

适合我