Can I turn off DataAnnotations checking in DefaultModelBinder?

I want DefaultModelBinder not to perform any validation based on the metadata of DataAnnotations. I already use DataAnnotations with DynamicData for the administration area of ​​my site, and I need a different set of validation rules for the MVC frontend.

I decorate my classes with the MetadataType attribute. If I had different MetadataType classes for the same model, but they were used in different scenarios, that would be great. If not, I'm fine by simply disabling the check in DefaultModelBinder, either setting some property, or creating a specialized version.

+4
source share
1 answer

Take a look at the ModelValidatorProviders.Providers collection and leave only the necessary entries.

ModelValidatorProviders.Providers.Clear() should fix your problem, but you should still look at it to see how it works.

+6
source

Source: https://habr.com/ru/post/1304313/


All Articles