Attention: We are retiring the ASP.NET Community Blogs. Learn more >

Contents tagged with Data Annotations

  • Performing Custom Validations Using Data Annotations

    ASP.NET MVC applications can use data annotation attributes to enforce validations on model properties. ASP.NET MVC provides a few data annotations that cover frequently needed validations such as [Required], and [StringLength]. However, at times you need to perform custom validations on the model properties. In such cases you can create a custom data annotation attribute and attach it with a model property. You can also add client side validation capabilities to your custom data annotation. This article discusses how this task can be accomplished.

  • Validating Data Using Data Annotation Attributes in ASP.NET MVC

    The data entered by the end user in various form fields must be validated before it is saved in the database. Developers often use validation HTML helpers provided by ASP.NET MVC to perform the input validations. Additionally, you can also use data annotation attributes from the System.ComponentModel.DataAnnotations namespace to perform validations at the model level. 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. This article discusses the basics of using these attributes in an ASP.NET MVC application.