In the comments on my previous post, Eric doesn’t like the idea of using exception-based validation.
My focus in the previous post on IDataErrorInfo and MVC wasn’t so much on the raising of exceptions to signal a validation violation or broken rule, but mainly on the perceived poor experience I get with IDataErrorInfo and validation frameworks.
Certainly you can avoid the exceptions by using TryUpdateModel instead of UpdateModel. Of course this doesn’t return the validation errors / broken rules so depending on your needs you may need to do validation once again just as you did so many times in the IDataErrorInfo members when using a validation framework [Note: you may not need to retrieve those validation errors / broken rules again if IDataErrorInfo meets all your validation needs because it adds the errors to the form via AddModelError as mentioned before.]. I am not going to repeat all the previous code ( check the previous post ), but here is just the idea of using TryUpdateModel which avoids the exception…
var customer = new Customer();
// Validation Passed…
// Validation Did Not Pass…
Hope that helps,