Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Client-side model-level or form level validation with ASP.NET MVC3

I am using ASP.NET MVC3 with jQuery Validate + the unobtrusive validation support that comes with MVC3. Works great for almost everything, but I have one view where there is some view-wide validation that I need to do and I am not sure how to tap into the validation events that happen as part of MVC3+Validate+Unobtrusive. The actual validation will take just a few lines of code. I just don't know where to plug in that code.

I would like to tie into existing validation flow so that when the standard validation finds errors with individual fields and adds warning messages for them, my form-wide error message will also appear in the validation summary.

P.S. I am clear how to add appropriate model-level validation on the server side (Scott just blogged about it), but I feel it would be strange if some validation happened on the client and others only on the server. A user might see the client validation errors, fix them, then try to submit the form and only then get the model-level validation error message.

like image 213
Erv Walter Avatar asked Nov 26 '22 12:11

Erv Walter


1 Answers

I would say what you are looking for is the new support for Remote Validation in Asp MVC3. Here is an article describing a common scenario, hopefully you can extend it yourself. Otherwise there are probably other articles around explaining it even better ;-)

http://www.aaronstannard.com/post/2010/12/07/remote-validation-asp-net-mvc3.aspx

/Victor

like image 180
Victor Avatar answered Dec 10 '22 21:12

Victor