views:

212

answers:

1

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.

+6  A: 

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.

LukLed
Excelent. This is what I'm using on Application_Start: `ModelValidatorProviders.Providers.Remove(ModelValidatorProviders.Providers.Single(p => p is DataAnnotationsModelValidatorProvider));`
Max Toro
@Max Toro: That should work fine, but you propably don't need IDataErrorInfo validation too.
LukLed