views:

72

answers:

1

Does the latest ASP.NET MVC 2 validation allow contextual validation? I'm looking for something similar to Castle Validator's "RunWhen" property. It allows you to declare that a validator should only be executed in a particular context.

The most obvious use is for Identity fields. The following would specify that the int ID field is required, but only for updates (maybe for deletes too). It should never be required on an insert, however.

[Required(RunWhen=RunWhen.Update)]
public int ID {...}

This seems like a very common scenario. How can this be handled with the out-of-the-box asp.net mvc 2 validation?

A: 

No out of the box, but you can plug Yourself in. Read this one.

Alexander Taran