Error in jquery.validate.js in MVC 4 Project with

2019-01-13 05:28发布

I created a new ASP.Net MVC 4 project using the template in Visual Studio 2012. After upgrading to jQuery 1.9, the login functionality breaks. Specifically, I get the error

0x800a138f - JavaScript runtime error: Unable to get property 'call' of undefined or null reference

at line 1172, column 5 in jquery.validate.js

How can I fix this issue?

7条回答
疯言疯语
2楼-- · 2019-01-13 05:38

Replacing the bundles script path by the following line worked for me.

 <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryval")"></script>

I tried updating the jquery validation via Nuget, and also updated the jquery to 2.0 version, but none of those solution worked. The only one that worked fine without downloading anything Pre version was the solution proposed by Texellab

查看更多
放荡不羁爱自由
3楼-- · 2019-01-13 05:47

I had the same issue, no problem in firefox but ie still gives the error. I am using jquery-2.0.0; jQuery Validation Plugin 1.11.1

I found a fix: replace

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

with

@section Scripts{
    <script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl("~/bundles/jqueryval")"></script>
}
查看更多
爷、活的狠高调
4楼-- · 2019-01-13 05:47

The underlying problem is that some methods that had been deprecated since jQuery 1.7 (when new, improved methods were added) have been removed in 1.9. jQuery Validate has, apparently, not been updated so it uses the new methods instead. I found that using the jQuery Migrate Plugin, which puts the removed methods back in, solved my problems with this.

查看更多
爷的心禁止访问
5楼-- · 2019-01-13 05:57

If you install jQuery.Migrate 1.1.1 then it will work fine with jQuery.Validation 1.11, jQuery 1.9 and 2.x.

As well as doing install-package jQuery.Migrate, you must then add the JavaScript to BundleConfig.cs - I added it just after jQuery and this is what the line that registers jQuery looks like now:

bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
  "~/Scripts/jquery-{version}.js",           // jQuery itself
  "~/Scripts/jquery-migrate-{version}.js")); // jQuery migrate
查看更多
甜甜的少女心
6楼-- · 2019-01-13 05:58

Here's another solution:

I used MVC 3 with jQuery 1.71 and jQuery UI 1.8.20. I used the jQuery UI Tabs widget and setup each tabbed area to load a partial page that contained input fields.

Works great in Firefox v22 and Chrome v28, fails in IE10. The error I got was 'Unable to get property 'settings' of undefined or null reference'

The resolution was to go to the partial forms and comment out the following code:

<script src="@Url.Content("~/Scripts/jquery-1.7.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>*

It now works successfully in all browsers.

查看更多
在下西门庆
7楼-- · 2019-01-13 06:02

The issue is the line of code inside of the validation script

$.event.handle.call(this,e);

The problem here is with $.event.handle. Both this and e have proper values. jQuery deprecated $.event.handle in favor of jQuery.event.dispatch according to the migration script http://code.jquery.com/jquery-migrate-1.2.0.js.

Fixing these errors is as easy as simply replacing the reference to handle with dispatch.

This can be wrapped in a document.ready callback to ensure it runs after the other scripts run.

$(function(){
    jQuery.event.handle = jQuery.event.dispatch
});
查看更多
登录 后发表回答