Using ASP.NET MVC v2 EditorFor and DisplayFor with IEnumerable Generic types

后端 未结 6 804
情话喂你
情话喂你 2020-12-07 22:51

I have a IList as a property named Tags in my model. How do I name the files for display and editor templates to respect it when I call

6条回答
  •  长情又很酷
    2020-12-07 23:15

    EditorFor or DisplayFor is access ViewData.Model property.

    Sample solution

    <% foreach(var tag in Model.Tags) { %>
    <%= Html.EditorFor(m => tag) %>
    <% } %>
    

    Other solution

    <% for (var i=0;i
    <%= Html.EditorFor(m => m.Tags[i]) %>
    <% } %>
    

    Hope this code!

提交回复
热议问题