Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC Client Side Validation

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?

like image 354
Elijah Manor Avatar asked Sep 30 '08 13:09

Elijah Manor


2 Answers

"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!

like image 70
Brian Vallelunga Avatar answered Oct 13 '22 10:10

Brian Vallelunga


I agree with other posters, client side validation is strictly for improving user experience.

Check out the JQuery Validation plugin. It's super easy to get started with basic validation -- literally one line of JS plus adding class names to the input controls. It's also very powerful. You can extend to do whatever you want.

like image 28
Tim Scott Avatar answered Oct 13 '22 11:10

Tim Scott