home / software / tips and tricks / How to create a client side custom ValidationAttribute in MVC 3?

How to create a client side custom ValidationAttribute in MVC 3?

Updated:  08/18/2013 06:08 AM
Author:  Shiju Mathews

Status:    Resolved.


Step 1
Complete the server side custom ValidationAttribute, Refer How to create a custom ValidationAttribute in MVC 3?

Step2
Add a reference System.Web.Mvc to class GraterThanDateAttribute Implement IClientValidatable in class GraterThanDateAttribute

Step 3
Implement the method GetClientValidationRules in class GraterThanDateAttribute


Step 4

Add a new javascript file named “CustomValidations.js” to the “Scripts” folder. Make sure that the Script folder contains jquery.validate.unobtrusive.js, jquery-1.4.4-vsdoc.js and jquery.validate-vsdoc.js. Add the following code to CustomValidations.js


Step 5
Add the script file to the view where we are going to use the model.


Step 6

Run the project from visual studio and navigate to the proper view. Check for client side validation on the page.
Tags: How to create a client side custom ValidationAttribute in MVC 3?
Updated on: March 2024