The cool jQuery validation plug-in ASP. NET MVC

Source: Internet
Author: User

Code: http://down.51cto.com/data/187446

Before reading this article, I hope you can read it first. I will use jquery plug-in author blog: http://www.position-absolute.com/articles/jquery-form-validator-because-form-validation-is-a-mess/

Download the package and decompress it to a certain place.

1. Create an asp.net mvc 3 Project:

2. Add the required js and css files to the project (in the directory you just decompressed ).

3. Create a model named user, which contains three attributes. All attributes are required.

Then we create the corresponding Controller

4. Html Helper Extension

This is the most exciting part. We have extended the html helper and used reflection to find whether the current Model attribute is required. If required, we will write an html code to the page as a prompt for verification.

5. Add js and css to the template. The layout page is in Razor:

The last part is our view:

@ Html. Editor () This extension method will generate html. The important thing is that we need to use the bottom section to verify the current form, through form id ....

Run the following command to view the result:

Amazing

This is a good verification solution for the entire project. Of course, it can also verify other controls. For details, refer to the example in the code you downloaded.

Link: http://www.cnblogs.com/n-pei/archive/2011/04/11/2011964.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.