I’ve been directed to an very nice article that shows how to create a Custom Validator from start to finish. My only problem is that this only works on single fields:
http://haacked.com/archive/2009/11/19/aspnetmvc2-custom-validation.aspx
What if I need to validate against 2 or more properties in my Model? How can I pass my entire Model into the Validator?
NOTE: To be clear, I really don’t want to have to resort to validating the entire model on post back… that would defeat the purpose of this method.
You need to use a custom validate attribute and decorate your model with it, not individual properties:
and then decorate your model with it:
As an alternative to data annotations to perform validation I would more than strongly recommend you FluentValidation.NET. It also has great integration with ASP.NET MVC.