ASP.Net MVC2 Client and Server Validation sharing the same code - is it possible?

Posted by RemotecUk on Stack Overflow See other posts from Stack Overflow or by RemotecUk
Published on 2010-03-23T17:35:26Z Indexed on 2010/04/03 7:13 UTC
Read the original article Hit count: 480

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.

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about asp.net-mvc-2