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?
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With