This tutorial helps you to understand how you can use DataAnnotation attributes for validation of model data.
DataAnnotation namespace All DataAnnotation attributes are included in System.ComponentModel.DataAnnotations namespace. Various DataAnnotation attributes give you a simple way to perform validation on model data. These attributes are helpful for common validation patterns like Required, Range, StringLength, etc. It can perform validation on both the client and server side.
-
Customer Model - with Data Annotation attributes applied on customer properties.
-
Home Controller - having Customer models used with Data Annotation validation.
Below image shows validation erros triggered by Data Annotations
For more details visit - https://geeksarray.com/blog/how-to-validate-mvc-model-using-dataannotation-attributes