Javascript – ASP.NET MVC Client Side Validation

asp.net-mvcclient-sidejavascriptvalidation

I am all about using ASP.NET MVC, but one of the areas that I hope gets improved on is Client-Side Validation.

I know the most recent version (Preview 5) has a lot of new features for Validation, but they all seem to be after the page has been posted.

I have seen an interesting article by Steve Sanderson… using Live Validation, Castle.Components.Validator.dll, and a Validator framework he made.

I have used it in my project, but I am hoping something like it will get integrated into the official ASP.NET MVC release. I definitely think the business rules should reside either on the model or in the controller rather than in the View.

Have any of you used a similar approach?

Are you aware of something like this being added to the official ASP.NET MVC release?

Best Answer

"Obviously you'll still need to validate your input on the server side for the small percentage of users who disable javascript."

Just an update to this comment. Server-side validation has nothing to do with users that run with JavaScript disabled. Instead, it is needed for security reasons, and to do complex validation that can't be done on the client. A form should always have server-side validation. Client-side validation is only there as a convenience.

A malicious user could easily post data to your form bypassing any client-side validation that you have in place. Never trust input data!