Well, this is a mouthful to describe.
Here’s an example concept I came up with during the early ASP.Net MVC 3 days.
I wanted to be able to use the unobtrusive client side model validation forms in a partial view but load them via jquery ajax calls.
In addition, I had some quite complex server side validation that needed to be done.
The catch? Those complex server side calls HAD to always be server side AND they should not cause the form to reload. So, Custom Validators didn’t seem to work the way I wanted (bear in mind that the information on on mvc3 was pretty light).
The form gets hijaxed to preserve the unobtrusive validation.
If the form’s model is invalid it returns the original form partial html.
If the form’s model is valid, we return a JsonResponseViewModel json object.
This object can have a status of “Ok” or “Error”.
If “Error”, then a list of JsonResponseErrors exists. We parse and display those on the client.
If “Ok” then just we are all good 🙂
There’s probably a better way to do this but I thought I should just share this with the world anyways.
The example solution:
ASP.Net MVC3 ajax based client side notification of server server side validation.
Also shows you how to load a standard MVC3 unobtrusive form via ajax and keep the MVC model validation for both server and client side.