This article discusses the basics of using these attributes in an ASP. Data annotation attributes are a set of attributes residing in the System. Data Annotations namespace that allow you to validate property values of a model class.
Once added they can perform validations on the server side as well as on the client side.
Data annotation attributes are attached to the properties of the model class and enforce some validation criteria.
They are capable of performing validation on the server side as well as on the client side.
For example, the [String Length] attribute used on the First Name property specifies the maximum length for First Name to be 50 and Minimum Length to be 3.
The Error Message property of the data annotation attribute indicates an error message that will be displayed in case there is any validation error.
The [Email Address] attribute validates a property for a valid email address.However, in this case our model class is an Entity Framework class.Since the data model class is automatically created for you by the Visual Studio designer it is not recommended to modify the same class file.The [Display Name] attribute is used to specify a friendly name for the property under consideration.This friendly name is used by HTML helpers such as Html. If you don't use the [Display Name] attribute a property name will be used for display purpose.Then add a new SQL Server database named User Db to the App_Data folder and create a table - User Profile.The User Profile table has columns as shown in the following figure: The User Profile table As you can see from the above model class, the User Profile table consists of eight columns, viz.Id, First Name, Last Name, Email, Bio, Age, Blog Url and Phone.Once you create the User Profile table make sure to add an ADO.The important data annotation attributes used for data validation are as follows: All of the above attributes also allow you to specify an error message that is displayed in the event of an error.If an error message is not specified, a default error message is displayed.