How to disable automatic ModelState Validation for a specific Controller / Action?
As th开发者_C百科e title mentioned, i want to disable automatic ModelState Validation for a specific Controller / Action.
Is that possible ?
Consider clearing the Modelstate
dictionary in the controller action instead by calling:
Modelstate.Clear();
I think it is possible. Create custom ModelValidatorProvider.
public class CustomModelValidatorProvider
: DataAnnotationsModelValidatorProvider
{
protected override IEnumerable<ModelValidator> GetValidators(
ModelMetadata metadata,
ControllerContext context,
IEnumerable<Attribute> attributes)
{
return Enumerable.Empty<ModelValidator>();
}
}
and set this provider at startup.
ModelValidatorProviders.Providers.Clear();
ModelValidatorProviders.Providers.Add(new CustomModelValidatorProvider());
How about this?
精彩评论