DataAnnotation JQuery seamless integration?
Seems like I have seen how this is done in the past, but I can't seem to find it now.
In Scott Gu's MVC V2 preview post he states they are shipping the JQuery validati开发者_如何学JAVAon plugin and soon you can use DataAnnotations to decorate your ViewModels and have a single place to specify client and server validation.
In a future ASP.NET MVC 2 preview we are planning to ship the jQuery Validation plugin as part of the default project template, and add support for the automatic client-side JavaScript enforcement of DataAnnotation validation rules as well. This will enable developers to easily add validation rules in one place on either a Model or ViewModel object, and have them be enforced both client and server-side everywhere it is used within the application.
I can't find how this is done or if it was ever implemented. Can someone enlighten me please?
If you're curious how this is implemented, you can check out Steve Sanderson's xVal framework.
http://xval.codeplex.com/
As noted on that page, xVal is no longer being actively developed and only intended for MVC v1 as a similar feature is implemented in MVC v2. Scott Guthrie talks about the feature in this post:
http://weblogs.asp.net/scottgu/archive/2010/01/15/asp-net-mvc-2-model-validation.aspx
and it is present in ASP.NET MVC v2 and v3. If you want to know how it is implemented in ASP.NET MVC v2, you can download the source code from here:
http://aspnet.codeplex.com/releases/view/41742
精彩评论