2

Is there a way to disable the automatic validation of a Model gets passed to a Controller... ?

2 Answers 2

2

The ModelValidatorProviderCollection allows you to control what kinds of validation providers your application will use. By default I believe it uses the DataAnnotationsModelValidatorProvider.

You could try clearing out the collection at application startup -- I've never tried it, but I would imagine that would disable validation for you.

protected void Application_Start()
{
    // Other startup code...

    ModelValidatorProviders.Providers.Clear();
}
Sign up to request clarification or add additional context in comments.

Comments

0

A bound model only validates (client side) out of the [MVC3] box. When you scaffold a view, jquery.validate.min.js and jquery.validate.unobtrusive.min.js are added to the view if you leave the "Reference script libraries" check box ticked. This will produce some client side validation.

If you remove the references to these scripts, the validation is not done server side (in your controller) unless you access:

ModelState.IsValid

You could have [Required] attributes, your own custom ValidationAttribute annotations, etc and the model will not be validated.

2 Comments

I have tried it, but cant confirm. My ValidationAttributes get validated without calling ModelState.IsValid.
@dknaack: What can't you confirm? Can you show some model code?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.