Recently I setup a new asp.net mvc application. After reading Steve Sandersonâ€™s new book â€“ in which he refers to his xVal library, I figured Iâ€™d take a look at it.
The main features of the xVal library is itâ€™s ability to apply validation that executes on the server side, as well as the ability to apply client side validation using the same technique. This is quite powerful.
On the client side, you can use the native asp.net MS library, or jQuery.
On the server side, there are also options available: DataAnnotations, Castle Validators, or even further, you can write your own IRulesProvider and attach rules programmatically.
I wonâ€™t go into â€˜howâ€™ to use the library, as Steve has given a great walk through here: xVal – a validation framework for ASP.NET MVC
The second part is the DataAnnotations â€“ which I was glad to have investigated some of Silverlight 3 to understand the concept. As mentioned in this post by Brad Wilson (DataAnnotations and ASP.NET MVC), â€œin .NET 3.5 SP 1, the ASP.NET team introduced a new assembly named System.ComponentModel.DataAnnotationsâ€¦â€
I think the real value here is this â€˜buddy classâ€™ concept that lets you use validation attributes on code generated classes, ie. Linq to SQL/Entity Framework. Basically you can add attribute metadata to the generated classes in partial classes. An example of this can be found here, Integrating xVal Validation with Linq-to-Sql
This is very powerful, in particular how the xVal library gives a developer several options to help apply validation to the model classes.