With MVC3 you have two new mechanisms for adding custom validation. These are (1) subclass ValidationAttribute or (2) implement IValidatableObject.
The ValidationAttribute allows you to add client side validation relatively simply by implementing IClientValidatable (and registering a new adapter and method via jQuery).
IValidatableObject is more suited to one-off validation requirements where reuse is not an option. It also results in slighlty simpler code. It would therefore be my choice for a number of scenarios. Unfortunately, I do not see an easy way of implementing client side validation using this method.
So the question is what am I missing and how DO you get JS validation when using IValidatableObject?
As I did not get a (valid) answer here, I asked a couple of people from Microsoft and they confirmed that it was not currently possible.
Brad Wilson:
Stuart Leeks:
This article describes a way to access the container object in client side validation in ASP.NET MVC. You can probaly use this to get started on using your own client side validation
http://weblogs.asp.net/scottgu/archive/2010/07/27/introducing-asp-net-mvc-3-preview-1.aspx http://blogs.msdn.com/b/stuartleeks/archive/2010/07/28/asp-net-mvc-adding-client-side-validation-to-validatepasswordlengthattribute-in-asp-net-mvc-3-preview-1.aspx