最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ASP.NET MVC Client Side Validation - Stack Overflow

programmeradmin0浏览0评论

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?

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?

Share Improve this question asked Sep 30, 2008 at 13:35 Elijah ManorElijah Manor 18k17 gold badges74 silver badges79 bronze badges 1
  • This is an exact repost of a previous question. – leppie Commented Sep 30, 2008 at 13:45
Add a comment  | 

5 Answers 5

Reset to default 18

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

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.

LiveValidation is another helpful javascript library that can help out. See an example (with ASP.NET MVC) here:

http://blog.codeville.net/2008/09/08/thoughts-on-validation-in-aspnet-mvc-applications/

It looks like this area will see lots of improvement in ASP.NET MVC 2

http://weblogs.asp.net/scottgu/archive/2009/07/31/asp-net-mvc-v2-preview-1-released.aspx

Have a look at this blog article. It describes how to automatically generate client-side validation rules with xVal and also how to automatically implement remote client-side validation.

发布评论

评论列表(0)

  1. 暂无评论