Code: http://down.51cto.com/data/187446
Before reading this article, I hope you will be able to read the plugin author blog that I'll use to get jquery: http://www.position-absolute.com/articles/ jquery-form-validator-because-form-validation-is-a-mess/
After downloading, unzip to a place.
1. Create a asp.net MVC 3 project:
2. Add the required JS and CSS files to the project (in the directory you just unzipped).
3. We create a model called user, contains 3 attributes, are required attributes.
Then we create the corresponding controller
Extension of the 4.Html helper
This part is the most exciting place. We extended the HTML helper, using reflection to find out if the current model property is required, and if required, write a section of HTML code to the page as a validation hint.
5. Add JS and CSS to the template, Razor is the layout page:
And finally, our view section:
@Html. Editor () This extension method will generate Html. And it's important that we use the following script to validate the current form, through the form ID ....
Run the next look at the results:
Amazing
This is a good validation program for the entire project. Of course, it can also be validated against other controls, please refer to the example of the code you downloaded.
Original link: http://www.cnblogs.com/n-pei/archive/2011/04/11/2011964.html
"Edit Recommendation"
- Share 24 very useful jquery Plug-ins
- Share 7 Fantastic sites for learning jquery
- jquery to realize the effect of human-simulated network pop-up layer
- jquery Drag layout implement sort results Sync database
- 30 Latest awesome jquery light box plugin
"Responsible editor: Chen Yu new TEL: (010) 68476606"