In the scenario that your MyType
for instance doesn't have a default constructor (the default modelbinder needs a default constructor).
This can happen if you use the factory method pattern for creating a new object (very simple example just for illustration ;-):
public class MyType
{
private MyType() // prevent direct creation through default constructor
{
}
public static MyType CreateNewMyType()
{
return new MyType();
}
}
Then you would have to implement a custom modelbinder which calls the factory method CreateNewMyType()
instead of creating a new MyType
through reflection:
public class MyTypeBinder : DefaultModelBinder
{
protected override object CreateModel(ControllerContext controllerContext,
ModelBindingContext bindingContext,
Type modelType)
{
return MyType.CreateNewMyType();
}
}
Also if you're not happy with the current functionality or implementation of the default modelbinder, then you can easily replace it with your own implementation.