In MVC you can create an editor template for T
and then when you want to render an editor for a property of type IEnumerable<T>
you can simply do e.g.
Html.EditorFor(m => m.MyListOfT)
The beauty of this is that names are automatically created by the framework for the inputs, and then when posting back the model binding all works nicely.
My question is: how do you do the above when you have more than one type of editor template?
I've tried using UIHint(), however it only seems to allow you to specify the UIHint against the list, rather than each item in the list. This means you then have to create an EditorTemplate for the list, with a foreach() loop, and you then miss out on the nice auto-naming and model binding.
What am I missing here?
The Model is e.g.
public class MyViewModel
{
public IEnumerable<SomeType> SomeProperty { get; set; }
}
Ideally I want to do something like:
public class MyViewModel
{
[UIHint("SomeTypeTemplate")]
public IEnumerable<SomeType> SomeProperty { get; set; }
}
and have that automatically apply to all elements in the list so I can render with just:
Html.EditorFor(m => m.SomeProperty)