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

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

    Use the attribute [UIHint("Tags")] then create a display template called Tags.ascx in the DisplayTemplates folder.

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

    And in the file Tags.ascx

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl>" %>
    
         
     
    热议问题