I am developping my first application in Asp. I am using the environment Asp.NET MVC 3. I have a controller Action that has a single parameter. The type of this parameter is a complex object.
public ActionResult MyAction(ComplexObj obj) {
//TODO: using obj
}
I am using a ModelBinder class. But I am not sure if I should override the BindModel function or the CreateModel one.
What's the difference beween those two functions and when they are used exactely by the rooter.
Thanks !
What's the difference beween those two functions and when they are used exactely by the rooter.
BindModel
is the main method that does all the work in the model binding process and on the way it calls the CreateModel
method to provide an instance of the model based on the passed type. The CreateModel
method checks the model type whether it is a dictionary
or list
or a simple model and finally returns an instance by calling,
Activator.CreateInstance(typeToCreate);
Usually you have to go for overriding the BindModel
method and unless you say your requirement it's diffcult to say which one to override. If all you care about is to only override the way the model instance is created then you have to go for CreateModel
.