Meta

Tag: MVC4

This is a two part piece on working with Interfaces in MVC via the Html.EditorFor helper.

The first part – “Display” just covers one of those things I tried on the off chance, and was rather surprised that it worked right out of the box.

In the second part I’ll have a look at the next step of the process – binding these interfaces back to their models.

For reference, I’m working with MVC4, in VS 2012 For Web. I think this will also work in MVC3 at least.

Background

For a slightly messy user interface I’m working on, I wanted to be able to have a Model that holds a list of classes that implement an interface.

There is a possibility that all the classes might not be the same, and I was concerned that I was going to end up with a messy switch statement in my View that called the right Partial depending on which class I found in the list, and that this switch might need to be maintained on an on-going basis.