dknaack
dknaack

Reputation: 60468

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 ?

Upvotes: 6

Views: 2113

Answers (2)

Christopher
Christopher

Reputation: 517

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

Modelstate.Clear();

Upvotes: 3

takepara
takepara

Reputation: 10433

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?

Upvotes: 2

Related Questions