Tag: display templates

ASP.net MVC – 显示模板的集合

我在MVC中有以下模型: public class ParentModel { public string Property1 { get; set; } public string Property2 { get; set; } public IEnumerable<ChildModel> Children { get; set; } } 当我想要显示父模型的所有孩子时,我可以这样做: @Html.DisplayFor(m => m.Children) 然后,我可以创build一个ChildModel.cshtml显示模板,DisplayFor将自动迭代列表。 如果我想为IEnumerable创build一个自定义模板呢? @model IEnumerable<ChildModel> <table> <tr> <th>Property 1</th> <th>Property 2</th> </tr> … </table> 如何创build一个具有IEnumerable<ChildModel>模型types的显示模板,然后调用@Html.DisplayFor(m => m.Children)而不抱怨模型types错误?