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.
Great stuff