简体   繁体   中英

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

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.

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM