How can I reference the default model binding in a custom binder in the MVC4 Web API?

I recently asked a question here about a stack overflow about finding the right extensibility point for model binding in the beta version of the web API. Using a custom provider / IModelBinder gives me full control of model binding and access to cost providers.

However, this is really too much control. I just want to control how multiple values ​​are matched, and I don't want to bind a code model to hand-held code, which otherwise would work fine.

Ultimately, this is what I would like to do:

 public class MyCustomModelBinder : IModelBinder { public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext) { // Invoke default model binding // Pull out custom values var value1 = bindingContext.ValueProvider.GetValue("value1"); var value2 = bindingContext.ValueProvider.GetValue("value2"); bindingContext.Model.Value1 = DoCustomStuff(value1); bindingContext.Model.Value2 = DoCustomStuff(value2); return true; } ... // Define DoCustomStuff } 

It seems that it is rather difficult to get the default provider for WebAPI. Does anyone know if it is available and how you can get it here in a special connecting device?

+8
asp.net-web-api
source share
1 answer

I'm not sure about the web API, but in MVC you can inherit from DefaultModelBinder and call base.BindModel

-one
source share