Model-level validation

asp.net-mvc, c#, data-annotations, validation

Solution

There's a good example for this in the RegisterModel that comes with the latest asp.net mv 2.

Look at the "PropertiesMustMatch" attribute and its usage.

Problem

How does one accomplish "model-level" validation as stated in Brad Wilson's post: Finally, if you want a validation to have access to multiple properties, then make it a model-level validation (so that it gets the entire model as the model parameter, rather than a single individual property value). From http://forums.asp.net/p/1457591/3650720.aspx I tried to do the following ``` [MyCustomValidation("SomeStuff")] public class MyClass { // properties } ``` Breakpoints place in the `IsValid` override of `MyCustomValidation` trigger nothing, the code just continues. Breakpoints in the constructor of `MyCustomValidation` work, but nothing after that. Is this not what `model-level validation` refers to? UPDATE: dirtygopher's link to http://bradwilson.typepad.com/blog/2010/01/input-validation-vs-model-validation-in-aspnet-mvc.html shows model validation, the only issue is that the validation attributes are placed on the child properties of the parent class. I'm looking for a way to place `validation-attributes` directly to the class as I demonstrated in my above example.

Original source