The available properties are as follows:
Data Annotation Validator Attributes DataType
Specify the datatype of a property DisplayName
Specify the display name for a. DisplayFormat
Specify the display format for a property like different format for Date Proerty. Required
Specify a property as required. reqularexpression
Validate the value of a property by specified regular expression pattern. Range
Validate the value of a property with in a specified range of values. Stringlength
Specify min and max length for a string. MaxLength
Specify max length for a string. Bind
Specify fields to include or exclude if adding parameter or form values to model properties. Scaffoldcolumn
Specify fields for hiding from editor forms.
The specific usage is as follows:
Using System.ComponentModel;
Using System.ComponentModel.DataAnnotations;
Using SYSTEM.WEB.MVC; namespace Employee.models {[Bind (Exclude = "EmpId")] public class Employee {[Scaffoldcolumn (false)] public int Empi
d {get; set;}
[DisplayName ("Employee Name")]
[Required (errormessage = "Employee Name is Required")]
[Stringlength (100,minimumlength=3)] public String empname {get; set;}
[Required (errormessage = "Employee address is Required")]
[Stringlength] public string Address {get; set;}
[Required (errormessage = "Salary is Required")]
[Range (3000, 10000000,errormessage = "Salary must is between 3000 and 10000000")] public int salary{get; set;}
[Required (errormessage = "Please enter your e-mail address")]
[DataType (Datatype.emailaddress)]
[Display (Name = "Email address")]
[MaxLength (50)] [RegularExpression (@] [a-z0-9._%+-]+@[a-z0-9.-]+\.[
a-z]{2,4} ", errormessage =" Please enter correct e-mail ")] public string Email {get; set;} }
}
For more information please refer to: http://www.dotnet-tricks.com/Tutorial/mvc/D8I4270712-MVC-Data-Annotations-for-Model-Validation.html