开发者

Asp.NET MVC 3 ModelBinding Validation

Is there a way to disable the autom开发者_运维问答atic validation of a Model gets passed to a Controller... ?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜