views:

35

answers:

1

I have created an OrderFormViewModel which looks something like

public class OrderFormViewModel 
{
    public IOrderDetails { get; set; }
    public IDeliveryDetails { get; set; }
    public IPaymentDetails { get; set; }
    // ... etc

    public SelectList DropDownOptions { get; set; }
    // ... etc

}

This goes to my Create view, where each section (ie delivery details, payment details... etc) is then passed to a partial view which captures the necessary fields.

I thought this was all quite neat until I ran it and realised of course that the MVC model binder doesn't know how to instantiate any of the interfaces.

Is there a way to resolve this somehow?

I'm also trying to learn DI using Unity container, so I'm tyring to avoid having references to any concrete classes in my UI project (model is in a separate project).

+1  A: 

One solution is to make a custom model binder, but this path means you will need to go through the effort of translating form elements to properties on your object. However, you have complete control over which implementation of IOrderDetails gets used, for example, or you can have your DI give you the right concrete type using it's configuration.

Tejs