0.[displayname ("name")]
0. [DisplayName (" name ")]
1.[required]: Must be entered
" Please enter user name ")]
2.[stringlength]: Limit string length
[Stringlength ( length cannot exceed 10 characters ")]
3.[range]: Limit the range of values
1 [range (0, errormessage = " age range between 0-120 years old ")]
4.[regularexpression]: Must conform to a regular expression (1) to write an expression directly using RegularExpression:
1 [RegularExpression (@ "^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$"" Please enter email format ")] 2 Public Getset; }
(2) Custom features:
1 Public class Emailattribute:regularexpressionattribute 2 { 3public emailattribute () 4 : Base(@ "^\w+ ([-+.] \w+) *@\w+ ([-.] \w+) *\.\w+ ([-.] \w+) *$") 5 { 6 } 7 }
Comparison of 5.Compare Judgments
Public string Get Set ; } [Compare ("email"" email ")] Public string Get set; }
6.remote:ajax Remote Authentication, the return value is bool type TRUE indicates validation passed
//action method Controller class request mode[Remote ("User","Validate", HttpMethod ="Post", errormessage ="user name already exists")] Public stringUserName {Get;Set; } //.... PublicActionResult User () {//.. if(true) { returnJson (true, Jsonrequestbehavior.allowget); } Else returnJson (false, Jsonrequestbehavior.allowget); }
7.OutputCache Page Caching
[OutputCache (duration=)] // Set page Absolute cache Cache Time is 20 sec public actionresult Index () { // Verbose Code }
8. Hide Fields
[Hiddeninput (displayvalue=false)] Public string Get set; }
Introduction to common built-in validation features for ASP. NET MVC