Using Interfaces in action signature
- by Dmitry Borovsky
Hello, I want to use interface in Action signature. So I've tried make own ModelBinder by deriving DefaultModelBinder:
public class InterfaceBinder<T> : DefaultModelBinder
where T: new()
{
protected override object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)
{
return base.CreateModel(controllerContext, bindingContext, typeof(T));
}
}
public interface IFoo
{
string Data { get; set; }
}
public class Foo: IFoo /*other interfaces*/
{
/* a lot of */
public string Data { get; set; }
}
public class MegaController: Controller
{
public ActionResult Process(
[ModelBinder(typeof(InterfaceBinder))]IFoo foo){/bla-bla-bla/}
}
But it doesn't work.
Does anybody have idea how release this behaviour? And yes, I know that I can make my own implementation of IModelBinder, but I'm looking for easier way.