Data annotations and validation

Source: Internet
Author: User

1, first to understand why the server-side verification. Be aware that the information from the network is not trustworthy.

2, although the background can be verified, but there is no front-end so good experience or convenience.

3, the integration of the pros and cons, the MVC framework can help deal with these trifles.

4, understand the MVC data annotation related content.

General characteristics: Required, which refers to a validation error that is thrown by the Required attribute when the value of the property type is null or empty, such as [Required]

Stringlength, this attribute means that when the value of a property type is longer than the set value, a validation error is thrown, such as [Stringlength (160,mininumlength=3)], where the maximum length is set, and the minimum length is set.

Range, which refers to the maximum and minimum value of a value when the property type is used, such as [Range (5,30)]

Special use: Remote, which can take advantage of server-side callback functions to execute the client's validation logic. Usage such as

[Romote ("Checkusername", "account")]

public string Username{get;set;}

The controller writes the remote Checkusername code.

Public Jsonresult Checkusername (string username)

{

var result=membership.findusersbyname (username). count==0;

Return Json (Result,jsonrequestbehavior.allowget);

}

Compare, this feature is mainly used for

Data annotations and validation

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.