Data Annotation/Validation:-

One of the main challenges for the developer is validating the user input. You not only focus on validating the user input at the client side, it also needs to be validated at the server side.

You also need to take care about the showing the proper user friendly error message associated with validation logic.

In MVC application, when we talk about the validation, we mainly speaking about the validation the ‘model’ values. ASP.Net provides good features to validate the user input.

Instead of addling lines and lines of code to validate, you can apply validation with single attribute.

Asp.Net provides the declarative style of validation using attributes known as Data Annotation.

Example:

             
        [Required]
        [Display(Name = "User name")]
        public string UserName { get; set; }