ASP.NET MVC 3 and jQuery validation
What is the best way to do validation in MVC 3? Here are the requirements:
- Works client 开发者_如何学Cand server side.
- Shares as much code between client and server as possible (attribute on model property seems ideal)
- Works across async request
- Display errors, validation messages, and success messages coming from the server side
- Unobtrusive javascript, as minimal as possible
- Dynamically added HTML should still validate the same way
My task this weekend is to build a robust solution for this, figured I'd ask here first before re-inventing or re-discovering the wheel with blood sweat and tears.
I would check out Brad Wilson's blog on this. He covers using unobtrusive validation in MVC3, sounds like exactly what you're looking for.
Adding more info per OP's comment
Regarding server side validation (custom validation), check out @jfar's response to a similar question I posted regarding custom validation -- he suggests that you should question your design if you're relying heavily on custom validation. In my case, I ended up going either with Ajax to handle my custom validation, or allowed the postback to perform the validation.
精彩评论