Max Toro
Max Toro

Reputation: 28608

Can I disable DataAnnotations validation on DefaultModelBinder?

I want DefaultModelBinder not to perform any validation based on DataAnnotations metadata. I'm already using DataAnnotations with DynamicData for the admin area of my site, and I need a different set of validation rules for the MVC based front-end.

I'm decorating my classes with the MetadataType attribute. If I could have different MetadataType classes for the same model but used on different scenarios that would be great. If not I'm fine with just disabling the validation on the DefaultModelBinder, either by setting some property or by creating a specialized version of it.

Upvotes: 4

Views: 2341

Answers (1)

LukLed
LukLed

Reputation: 31842

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

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

Upvotes: 7

Related Questions