Reputation: 24325
I am validating models in ASP.NET MVC, and throwing a custom Exception that contains a list of those errors. Is this a preferred, best practice, or should I return a strongly typed list of errors instead of using a throw new CustomException(List errors). I catch these errors regardless in my OnException in the BaseController to handle an ajax request or post back.
Upvotes: 1
Views: 2079
Reputation: 191048
No. You should use ModelState
to store your validation errors. Exceptions should only be used in exceptional cases.
ModelState
has IsValid
and will return false
if there are any errors.
Upvotes: 5