ASP.NET xVal Library with DataAnnotations

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  🙂

Advertisements

2 thoughts on “ASP.NET xVal Library with DataAnnotations

  1. Hey Steve,

    Saw your comments about Google Wave on Tim Heuer’s blog, came here to say “loved it” (even blogged about it).

    Also pleased to see this post on xVal – just what I was looking for the past few weeks! Also love the links you hang off here.

  2. Hello. I hope you dont mind me posting on your blog. I wanted to let you know directly but I cannot find your contact info. I want to subscribe to your blog for updates but I cannot find your RSS subscription button. Please assist. Thanks in advance.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s