In my application I am using Entity Framework 4.0 for an ORM and I have a model metadata class defined for a Student in the models. I am using DataAnnotations for validations, and it's worked great. But I had a few instances where I needed custom validation attributes, because they applied to the class, not to individual properties. I created these, and tested them, they work perfectly in the sense that the form just keeps refreshing on submit until you fix the errors and lets you submit properly when they're fixed. But no error messages were shown.
I've been pulling my hair out trying to figure this out, and tried many different things. I was using ValidationSummary(true, "Creation unsuccessful, please correct the errors and try again") in the Create view, for instance. I changed the first parameter to false just in case my errors were being treated as property errors.
When I submit on a blank form, the validation summary simply lists all the property-level validation messages. However, when I fill all those in so only my class-level validation is left, and resubmit, my 4 error messages are in validation summary. I thought the list might just have been too long, but it isn't. I filled in all the properties correctly except one, and it just displayed one property error, then when I fixed it and submitted again it displayed my error messages.
I used the PropertiesMustMatch attribute as a basis for my attributes. I even put that attribute on my class and just tried to make it so the student's first and last name had to be the same as a test. It was the exact same behavior, works functionally, no error message.
Can someone please explain to me why my model-level errors are being treated as property errors? IntelliSense says the first property of ValidationSummary() is excludePropertyErrors, which sort of indicates to me it can display model level errors? Am I just mistaken?