I have basic client-side validation working in my MVC3 RC2 application, but I’m now interested in recommended practices for conveying server side validation errors, as well as server side exceptions, to the client. I know I can add properties to my view model and display these if populated, but I don’t want to reinvent the wheel, and I would like to tie in with MVC’s way of doing things. So, how should I, a) notify the user of server side validation errors, and, b) notify the user of server side exceptions, e.g. update failed due to duplicate key.
I have basic client-side validation working in my MVC3 RC2 application, but I’m now
Share
a) notify the user of server side validation errors
if
ModelState.IsValidis false redisplay the edit/insert view. The view should useValidationMessageForto display the error message (they will do nothing if there are no error messages so you can always have them in the view)b) notify the user of server side exceptions,
handle these errors and add a global error message, then use
ValidationSummaryto display that.