Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Compare Validator Problem and Solution in MVC3 with jQuery 1.8.1

5.00/5 (4 votes)
17 Jul 2013CPOL 15.9K  
Compare Validator is not working with latest jQuery lib while using with ViewModel in MVC

Introduction

In MVC3 for client side validation, we are using jQuery. It seems to be working for all the validations but I tried Compare Validator to compare ViewModel property with Model property and it was not working. In any case, it is saying it is not matched. I am using all the latest jQuery libraries. I did some Googling and found that it is a bug in jQuery and also found a solution which is given below.

Under the project, there is a jquery.validate.unobtrusive.min.js file. Search the following code in that.

JavaScript
f=a(b.form).find(":input[name="+d+"]")[0];  

Replace this line with the following line:

JavaScript
f=a(b.form).find(":input[name='"+d+"']")[0];    

After changing this, it works fine.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)