In my ASP.NET MVC project, I have a polymorphic collection that I wish to render - say, an IEnumerable<ISomething>
where the individual items may be a mix of different implementations of ISomething
.
I'd like that list rendered, where each concrete type renders according to its own template (perhaps a strongly typed ViewUserControl).
In WPF, I'd be able to specify DataTemplates that would automatically bind concrete types to specific templates. Can I do something similar in ASP.NET MVC?
Obviously, I can iterate through the list and attempt a cast using the is
keyword and then use a lot of if
statements to render the desired control, but I was hoping for something more elegant (like WPF).