Editor templates for list <line>

I am looking to create a generic editor for some basic models on my ASP.NET MVC3 site. Now they can contain strings, booleans, enumerations, and List collections. I want to expand the default editor templates to recognize List and show my own editor that can add and remove lines to this list. Everyone else is working fine.

How can I name the List.cshtml file, of course, is there a way to make this work? Also, why do enumerations not drop-down lists by default?

I know that I can create models with the name templates, but I do not know the class names until runtime.

Thanks for any help and recommendations.

+4
source share
1 answer

You can name the editor template Foo.cshtml , where Foo is the list type: List<Foo> . Then just:

 @Html.EditorFor(x => x.FooList) 

and if the FooList is an IEnumerable<Foo> , your editor template will automatically be displayed for each item in this list. Therefore, if you already have editor templates for basic data types such as String, Decimal, DateTime, ... when you do @Html.EditorFor(x => x.SomeList) , your editor templates will be picked up.

+13
source

Source: https://habr.com/ru/post/1343654/


All Articles