Site Meter

Monthly Archives: September 2009

xVal v1.0 Now Available

image xVal version 1.0 is released at last! In case you’re not aware, xVal is a validation helper for ASP.NET MVC that lets you use your own choice of server-side validation framework (e.g., Microsoft’s DataAnnotations attributes, or Castle Validator, or NHibernate Validaion) and dynamically generates client-side validation code from your rules.

You can download the library from If you want a working example of xVal in action, download the demo project or read the rest of this blog post.

So, what’s new in version 1.0?

  • Support for dynamic client-side validation summaries
  • Remote validation (i.e., evaluating rules via Ajax)
  • Additional language files for localised default validation messages: Danish, French, Dutch, Polish, Swedish, and Italian
  • Upgraded to work with jQuery 1.3.2 and jQuery.Validation 1.5.5
  • Fixes for some bugs and issues in version 0.8.

If you’d like to learn more about the basics of getting started with xVal, setting up rules, etc., check out my previous posts on the subject. In this post, I’ll describe only the new features and will assume you already know how to get started with xVal.

Client-side Validation Summaries

It’s the most commonly-requested feature, and it’s now here: you can display client-side validation messages in a “summary” format, just like ASP.NET MVC’s Html.ValidationSummary() helper does.

To do this, first make sure you’re rendering any server-generated validation messages into a standard ASP.NET MVC validation summary, and wrap that inside some element such as a DIV with some ID:

<div id="validationSummary">
    <%= Html.ValidationSummary("Please fix the following problems:") %>

Next, tell xVal that you want it to merge your client-generated messages into this summary by appending “.UseValidationSummary()” onto your existing call to Html.ClientSideValidation():

<%= Html.ClientSideValidation("booking", typeof(Booking))
        .UseValidationSummary("validationSummary") %>

That’s it! Just make sure that, when you call UseValidationSummary(), you pass the ID of the element containing your server-generated validation summary.

Note: This feature requires you to be using xVal with jQuery Validation (not ASP.NET Native validation) because internally, it’s built on a jQuery Validation feature. xVal makes your client-generated messages and your server-generated messages seamlessly fit together in a single summary list.

Remote (Ajax) Validation

xVal already supported standard client-side rules, custom client-side rules, server-side rules, and rules defined as combinations of these. But what if you want a rule that behaves like a client-side rule (so it’s evaluated dynamically before the user submits the form) but its logic actually has to run on the server? For example, if you want a “username must be unique” rule, you can’t do that with pure JavaScript because it requires a database lookup to evaluate.

Not surprisingly, “remote” rules fill this gap. All you have to do is say that a certain field is subject to remote validation, and provide an action method that can be called to validate any given input. It’s usually best to add a RemoteRule to an existing collection of rules directly in your view:

<%= Html.ClientSideValidation("booking", typeof(Booking))
        .AddRule("BookingDate", new RemoteRule(Url.Action("ValidateBookingDate"))) %>

Then, implement an action method that can validate some input. The action method will receive the complete contents of the form at the moment when validation is triggered, and can return its verdict in the form of a RemoteValidationResult, e.g.:

public RemoteValidationResult ValidateBookingDate(Booking booking)
    var error = Booking.ValidateBookingDate(booking);
    return error == null ? RemoteValidationResult.Success
                         : RemoteValidationResult.Failure(error.ErrorMessage);

That does the job. For an example of this in action, download the v1.0 demo project.


Note: I suggest adding RemoteRules as ad-hoc rules in your views (using .AddRule() as shown above) rather than embedding them directly in your domain model like most other rules, because they need to know the URL of the action method that evaluates them, and that information doesn’t really belong in a good technology-agnostic domain model.

Note: This feature also requires you to be using xVal with jQuery Validation (not ASP.NET Native validation) because internally, it’s built on a jQuery Validation feature. If there’s strong demand for supporting remote validation with ASP.NET Native validation, it will be done for a future release.

How to upgrade

If you’re already using an earlier version of xVal, upgrading should only take a minute:

  1. Download the 1.0 release package from Codeplex and unzip it
  2. In your project, replace xVal.dll and xVal.jquery.validate.js and/or xVal.AspNetNative.js with the latest versions you just downloaded

What about ASP.NET MVC v2?

The good folks at Microsoft have already said that ASP.NET MVC v2 will come with built-in support for generating client-side validation code from rules in an arbitrary server-side validation framework. That’s a familiar idea… :)

So should you use that instead of xVal? If it turns out to meet your needs better then yes, of course, and if it doesn’t, then no. Use whatever suits you best!

However it will be quite a while before MVC v2 is released – currently it’s still on CTP 1 – so one option is to use xVal now and consider migrating at the same time that you upgrade your entire project to MVC v2 if indeed you choose to do that. The migration path from xVal to MVC v2’s built-in validation should be reasonably straightforward, since the two approaches appear to be rather similar, and you can always retain the option of sticking with xVal if it suits you better.


Thanks to the following people who directly contributed to this release: House Air, Rodbv, Maarten Balliauw, Dariusz Tarczynski, Yoan80, Emmanuele, Eudega, and Howard van Rooijen.

kick it on

Review: Three Technical Podcasts I Subscribe To

If you’re the sort of developer who still thinks about software when you’re not at work, you might enjoy listening to one or more of the following podcasts. They’re all free and are a great way to fill your head with new ideas or distract you from a boring chore.

image Software Engineering Radio

My absolute favourite technical podcast, SE Radio, isn’t afraid to get deeply technical. The best aspect is its main host, Markus Voelter, who seems to have an amazingly clear grasp of so many aspects of software development – from what happens inside your CPU to what happens inside Fortune 500 company boardrooms – to the extent that his guests often struggle to keep up with his fast stream of insightful ideas, even though the guest is supposed to be the expert on the discussion topic.

This isn’t a .NET or Microsoft-specific podcast. Although .NET is a frequent topic of discussion, you’re just as likely to learn about current ideas in the Java space or about technology-agnostic architectural or academic concepts. SE Radio sets out to be “a lasting education resource, not a newscast.” As such, it’s quite serious, so is best suited for long car journeys rather than 10-minute bursts on the treadmill.

New episode frequency: Every 2 weeks
Best time to listen: During long journeys

Some particularly good episodes I can remember:

image .NET Rocks

Since 2002, Carl Franklin and Richard Campbell have hosted more than 450 (!) episodes of .NET Rocks. The typical show focuses on a specific Microsoft-related product or technology from the perspective of a .NET developer, and is about an hour long (though personally I never listen to the first 8 minutes or so – it’s banter about emails they’ve received or community events taking place around the USA – I always just skip ahead to the point where they introduce their guest).

The two presenters of .NET Rocks evidently have many years of software development experience, with an anecdote or war story on hand for every occasion. They have a fine grasp of the psychology of a coder and the ways that software and business interact, and are especially good at reminiscing about the old days and predicting where we’re heading.

The only downside to .NET Rocks is that their technical discussions never get deep or specific. When they have an interesting and fast-thinking guest, the presenters tend to hold them back and respond as if they don’t understand the points raised, perhaps because they think their listeners aren’t up to it. But hey, it’s free, and since they publish so frequently, there’s always something new to entertain you. Set your iPod to play at 2x speed and enjoy it…

New episode frequency: Every few days
Best time to listen: On the treadmill

Some particularly good episodes I can remember:


I only started listening to Scott Hanselman’s weekly podcast about a year ago, but it’s such a solid, reliably entertaining production that now I never miss a show. The episodes are fairly short – about 30 minutes – but they get right to the point. Overall the focus is on Microsoft-based web development,  but rather than cycling through the same old list of Microsoft technologies, Scott tends to cover development practices (e.g., agile development or code generation), specific open-source projects, and trends within the industry.

The main strength of Hanselminutes is that Scott is an excellent interviewer: even when his guests run out of interesting things to say (and you can tell when that happens), Scott always draws out an insightful new thread and gives the guest confidence to get back on track.

I’m struggling to think of any particular downside to this show, except perhaps that some guests seem to be on the show to promote a tool, book, development technique, or product, and I’d love to hear them more seriously challenged about the counterarguments to their product or practice. That’s just a vague feeling though – as a whole it’s well worth subscribing to.

New episode frequency: Every week
Best time to listen: During the morning commute

Some particularly good episodes I can remember:

Anyone got any other recommendation?