Data AnnotationsValidation in MVC can be done using Data Annotations that are applied to both the client and server side. Data Annotation attributes are used to validate the user inputs when posting the form. All the Data Annotation attributes like Required, Range are derived from the ValidationAttribute class that is an abstract class. The ValidationAttribute base class lives in the System.ComponentModel.DataAnnotations namespace.This article is showing how to create a custom Data Annotations step by step:
Step 1
Create a New MVC 4 Application.Step 2
Select Razor View Engine.Step 3
Here I am showing Email validation on the Employee Registration Form.Select the Model Folder then select Add New Item -> Add New Class CustomEmailValidator.cs.Here we need to inherit the ValidationAttribute and need to override the IsValid method.CustomEmailValidator.cs
Now run the application: Image 3 Image 4
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: