MVC 3 multiple DisplayFor-Templates

后端 未结 4 932
渐次进展
渐次进展 2021-02-07 12:54

I\'m trying to make a custom template for a basket item list. I need a few different templates, as I have different ways of displaying the item, depending on if it\'s on the web

4条回答
  •  有刺的猬
    2021-02-07 13:24

    Unfortunately that's a limitation of templated helpers. If you specify a template name for a collection property the template no longer applies automatically for each item of the collection. Possible workaround:

    @for (int i = 0; i < Model.Items.Length; i++)
    {
        @Html.DisplayFor(x => x.Items[i], "CustomerItemBaseList")
    }
    

提交回复
热议问题