9

From David Hayden's blog entry:

IValidatableObject Doesn't Always Fire

There is a gotcha here that may not be obvious. IValidatableObject in ASP.NET MVC 3 will not fire if there are property-level errors. As I mentioned, ASP.NET MVC 3 property validation occurs before object validation. If there are property errors, ASP.NET MVC 3 by design will not fire IValidatableObject so as not to return false positives ( thanks to Brad Wilson of Microsoft for confirming this today ).

For usability, I would like to get all of the validation messages in one collection on the object.

Is there a simple way to override this default behaviour without cracking open the MVC source?
I am currently trying to populate a ValidationContext object in the controller and calling object.Validate() in the else block of a:

if (TryModelUpdate(model))

P.S. Apologies if this is a duplicate, I haven't found anything similar on SO.

Community
  • 1
  • 1
StuperUser
  • 10,555
  • 13
  • 78
  • 137

0 Answers0