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

后端 未结 6 793
情话喂你
情话喂你 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:19

    I had the same problem today. Hope this helps:

    forach(var tag in Tags) {
        <%= Html.EditorFor( _ -> tag) %>
    }
    

    If you absolutely want to do sth. like

    Html.EditorFor(mymodel=>mymodel.Tags)
    

    Then you will have to:

    Create a UserControl (TagList.ascx) and add an UIHint attribute to MyModel

    class MyModel {
         [UIHint("Taglist")]
         IList Tags {get; protected set;}
    }
    

提交回复
热议问题