EditorTemplate Naming Convention for Collection model classes

后端 未结 1 1412
情书的邮戳
情书的邮戳 2021-01-21 13:24

I have a model property that is declared as type List.

public class MyModel
{
    List MyProperty { get; set; }
}
         


        
1条回答
  •  萌比男神i
    2021-01-21 14:04

    You could use the [UIHint] attribute:

    public class MyModel
    {
        [UIHint("TemplateForTheList")]
        public List MyProperty { get; set; }
    }
    

    or specify the template name as second parameter to the DisplayFor helper:

    @model MyModel
    @Html.DisplayFor(m => m.MyProperty, "TemplateForTheList")
    

    and then have a TemplateForTheList.cshtml template:

    @model List
    ...
    

    In this case the templating engine will not render the template for each element of the collection property. It will simply pass the collection itself to the template.

    0 讨论(0)
提交回复
热议问题