ASP.Net MVC2 Client and Server Validation sharing the same code - is it possible?
- by RemotecUk
With the excellent XVal by Steve Sanderson, it is possible to tell the client side validation to post the value being validated to the server using jquery. A method on the server then uses the same server side code you use for your server side validation, and returns simply a true or false to determine if the field is valid.
The advantage of this method is that you write your complex validation logic once in C# code and then put some JQuery plumbing in to tell your client page where to go to access your server validation.
I have been reading some blogs on MVC2 but no one seems to mention this functionality. Is it possible to tell the Microsoft MVC validation javascript to call a url validate data? Or do you have to write your own client side validation routines.
I should note that using the xVal method a custom validation to say if an email address is in use or not can be run from the client via a JQuery post which accesses the server side validation logic.