ASP.NET MVC 4 jQuery验证脚本包不工作(ASP.NET MVC 4 jQuery

2019-08-07 02:06发布

我已经recentely升级了网站使用ASP.NET MVC 4并有下面的代码来呈现我的jQuery验证包。

但我得到以下错误:

Microsoft JScript runtime error: Object doesn't support property or method 'live'

并单击文本框,当这个错误:

Unhandled exception at line 1234, column 5 in http://localhost:13112/Scripts/jquery.validate.js

0x800a138f - Microsoft JScript runtime error: Unable to get value of the property 'call': object is null or undefined

我的包代码:

    bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
                    "~/Scripts/jquery.unobtrusive*",
                    "~/Scripts/jquery.validate*"));

我_Layout.cshtml代码:

    @Styles.Render("~/Content/css")
    @Styles.Render("~/Content/themes/base/css")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
    @Scripts.Render("~/bundles/jqueryui")
    @Scripts.Render("~/bundles/modernizr")

这是我提供的HTML:

<link href="/Content/site.css" rel="stylesheet"/>

        <link href="/Content/themes/base/jquery.ui.core.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.resizable.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.selectable.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.accordion.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.autocomplete.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.button.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.dialog.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.slider.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.tabs.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.datepicker.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.progressbar.css" rel="stylesheet"/>
<link href="/Content/themes/base/jquery.ui.theme.css" rel="stylesheet"/>

        <script src="/Scripts/jquery-1.9.0.js"></script>

        <script src="/Scripts/jquery.unobtrusive-ajax.js"></script>
<script src="/Scripts/jquery.validate.js"></script>
<script src="/Scripts/jquery.validate.unobtrusive.js"></script>

        <script src="/Scripts/jquery-ui-1.9.2.js"></script>

        <script src="/Scripts/modernizr-2.6.2.js"></script>

有人能指出为什么这个错误可能会发生?

谢谢,亚历克斯。

Answer 1:

该方法.live已弃用jQuery中V1.7 +和jQuery的V1.9 +除去。

错误报告: http://bugs.jquery.com/ticket/13213
说明: http://jquery.com/upgrade-guide/1.9/#live-removed

.live()中除去

因为jQuery的1.7 .live()方法已弃用,在1.9已被删除。 我们建议您升级代码来使用。对()方法来代替。 完全匹配$( “a.foo”)。住( “点击”,FN),例如,你可以写$(文件)。在( “点击”, “a.foo”,FN)。 欲了解更多信息,请参阅。对()的文档。 在此期间,jQuery的迁移插件可以用来恢复.live()功能。

如何解决:下载的jQuery插件迁移 ,并把它添加到您的捆绑:

  bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
              "~/Scripts/jquery-{version}.js",
              "~/Scripts/jquery-migrate-{version}.js"));

更新:迁移插件现在可以从的NuGet还有:

PM>安装,包装jQuery.Migrate



文章来源: ASP.NET MVC 4 jQuery Validation Script Bundle Not Working