validation annotation features in model:
PublicClass Stuinfo {Publicint ID {GetSet;} [Display (Name ="Name")]Set the name of the field to display [Required (errormessage ="You need to fill in {0}")]Set as must field has been incorrectly prompted [Stringlength (Minimumlength =3)]Set maximum length and minimum lengthPublicString Name {GetSet;} [Display (Name ="Age")] [Range (1,ErrorMessage ="Age is not correct!" ")]Setting the range of valuesPublicint Age {GetSet;} [Display (Name ="Height")] [Range (typeofdecimal),"50.00","250.00", errormessage ="Height exceeds specified range")]PublicDecimal Height {GetSet;} [Display (Name ="Birthday")] [DataType (datatype.date,errormessage ="{0} format is incorrect")]Setting data types and error hintsPublic DateTime Birthday {GetSet;} [Display (Name ="Phone")] [Remote ("Checkphone","Stuinfo", errormessage ="{0} has been registered")]Validates the data in the channel (route) in the specified ConterollerPublicString Phone {GetSet;} [Display (Name ="Address")] [DataType (Datatype.multilinetext)]PublicString Address {GetSet;} [Display (Name ="E-mail")] [RegularExpression (@ "(\w) + (\.\w+) *@ (\w) + ((\.\w+) +)", errormessage ="{0} format is incorrect")]Regular validationPublicstring Email {get; set;} [Display (Name = //settings compare two field values public String Emailconfirm {get; set;} [Display (Name = "password")] [DataType (Datatype.password)] public string Password {get; set;} [Display (Name = "{0} format is incorrect")] public string email_b {get; set;}
Channels for Remote authentication:
Public Jsonresult Checkphone (string phone) { 0; return Json (result, jsonrequestbehavior.allowget); }
Effect:
The normal page:
The field validation effect is required:
Value range, value type validation effect:
Regular validation and comparison of field value effects:
Data type validation effect:
MVC4 data Annotations and validation