I\'m scratching my head a bit at how model binders do their work in ASP.Net MVC.
To be specific, the BindModel() method has a ModelBindingContext parameter that ho
The ModelBindingContext "knows" the type of model it's being handed because you have to either:
Example of ModelBinder attribute:
[ModelBinder(typeof(ContactBinder))]
public class Contact { ... }
Example of ModelBinders.Binders.Add():
void Application_Start()
{
ModelBinders.Binders[typeof(Contact)] = new ContactBinder();
}
If you have registered your ModelBinder and have implemented the BindModel method:
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { ... }
Query the ModelBindingContext.ModelType is equal to your Model e.g.
if (bindingContext.ModelType == typeof(Contact)) { ... }
Rehydrate your model from the ModelBindingContext.ValueProvider property to retrieve ValueProviderResult instances that represent the data from form posts, route data, and the query string e.g.
bindingContext.ValueProvider["Name"].AttemptedValue;
The following books were used ASP.NET MVC 2 in Action and ASP.NET MVC 1.0 Quickly