Validation in ASP.NET MVC is done by decorating model properties with attributes. There are some built-in validation attributes. For example, Required attribute ensures that there exists a value for the property. We can write custom validation attributes as well. In this post, we build a UrlValid attribute. When the user enters an URL in a TextBox, the UrlValid attribute verifies if the URL is active.…

Read More

Extension method extends an existing class. In this post, we will add an extension method to HtmlHelper class. The method display error messages.

Validation

Data annotations validates user input. An example is shown below.

[Required(ErrorMessage = "Please enter name")]
public string Name { get; set; }

Controller has the ModelState object. ModelState object has the validation errors. For each user input (eg.…

Read More