I\'ve been running some experiments with ASP.NET MVC2 and have run into an interesting problem.
I\'d like to define an interface around the objects that will be used
I had the same issue. The answer is instead of overriding BindModel() in your custom model binder, override CreateModel()...
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, System.Type modelType)
{
if (modelType == typeof(IPhoto))
{
IPhoto photo = new PhotoImpl();
// snip: set properties of photo to bound values
return photo;
}
return base.CreateModel(controllerContext, bindingContext, modelType);
}
You can then let the base BindModel class do its stuff with validation :-)