Data annotation are the attributes, which provide Server side validation and the framework also supports client side validation when we use one of the attributes on a model property. It resides in System.ComponentModel.DataAnnotations hierarchy. MVC supports the attributes given below.
- Required
- StringLength
- RegularExpresson
- Range
- Compare
- Remote
In Model class
- [Required]
- public string FirstName {
- get;
- set;
- }
- [StringLength(100, MinimumLength = 30)]
- public string LastName {
- get;
- set;
- }
- [Compare(“Email”)]
- Public string EmailConfirm {
- get;
- set;
- }
- [Remote(“CheckUserName”, ”Account”)]
- Public string UserName {
- get;
- set;
- }