开发者

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

I am using ASP.NET MVC3 with jQuery Validate + the unobtrusive validation supp开发者_如何转开发ort 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.


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


You should ALWAYS validate again on the server. Its really easy to circumvent javascript validation.

Rule #1 of Web Development: NEVER TRUST USER INPUT

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜