dknaack
dknaack

Reputation: 60556

Asp.NET MVC 3 ModelBinding Validation

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

Upvotes: 2

Views: 258

Answers (2)

ataddeini
ataddeini

Reputation: 4951

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();
}

Upvotes: 2

David Fox
David Fox

Reputation: 10753

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.

Upvotes: 0

Related Questions