How to disable model binding for one action method in asp.net mvc

442 Views Asked by At

We are using custom model binders, how to disable model binding for one action method, so that i can directly post data from angular http post request, I have taken different/new class as parameter for action method. but due to custom model binders loosing posted data.

1

There are 1 best solutions below

0
jefftrotman On BEST ANSWER

I don't think you can disable custom model binding for an action, but you can do it by (model) class type.

I'm guessing you've got something like this:

ModelBinders.Binders.DefaultBinder = new CustomModelBinderClass();

The Binders Property is a dictionary mapping (model) types to model binder classes, so if you can use a unique model type in this one scenario, you should be able to change back to the default binder for that model type like this:

var defaultBinder = new DefaultModelBinder();
ModelBinders.Binders.Add(typeof(ModelThatNeedsDefaultBinding), defaultBinder);