Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable automatic ModelState Validation for a specific Controller / Action?

As the title mentioned, i want to disable automatic ModelState Validation for a specific Controller / Action.

Is that possible ?

like image 332
dknaack Avatar asked May 31 '11 09:05

dknaack


2 Answers

Consider clearing the Modelstate dictionary in the controller action instead by calling:

Modelstate.Clear();
like image 54
Christopher Avatar answered Oct 11 '22 11:10

Christopher


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?

like image 20
takepara Avatar answered Oct 11 '22 09:10

takepara