ASP.NET MVC 4 jQuery验证脚本包不工作 [英] ASP.NET MVC 4 jQuery Validation Script Bundle Not Working

查看:186
本文介绍了ASP.NET MVC 4 jQuery验证脚本包不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经recentely升级网站使用ASP.NET MVC 4,具有以下code,以使我的jQuery验证包。

I have recentely upgraded a website to use ASP.NET MVC 4 and have the following code to render my jQuery validation bundle.

不过,我得到以下错误:

But I get the following error:

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

而在一个文本框中单击时,这个错误:

And this error when clicking in a text box:

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

我的包code:

My bundle code:

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

我的_Layout.cshtml code:

My _Layout.cshtml code:

    @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:

Here is my rendered 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>

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

Can someone point out why this error might be occurring?

谢谢, 亚历克斯。

推荐答案

该.live方法是去precated jQuery的V1.7 +和jQuery的V1.9 +删除。

The .live method has been deprecated in jQuery v1.7+ and removed in jQuery v1.9+.

错误报告: http://bugs.jquery.com/ticket/13213
说明: <一href="http://jquery.com/upgrade-guide/1.9/#live-removed">http://jquery.com/upgrade-guide/1.9/#live-removed

Bugreport: http://bugs.jquery.com/ticket/13213
Explanation: http://jquery.com/upgrade-guide/1.9/#live-removed

.live()删除

的.live()方法被德precated自jQuery的1.7,并已   在1.9中删除。我们建议您升级code使用。对()方法   代替。要完全匹配$(a.foo)。生活(点击,FN),例如,   你可以写$(文件)。在(点击,a.foo,FN)。欲了解更多   信息,请参阅。对()的文档。在此期间,所述的jQuery   迁移插件可用于恢复.live()功能

The .live() method has been deprecated since jQuery 1.7 and has been removed in 1.9. We recommend upgrading code to use the .on() method instead. To exactly match $("a.foo").live("click", fn), for example, you can write $(document).on("click", "a.foo", fn). For more information, see the .on() documentation. In the meantime, the jQuery Migrate plugin can be used to restore the .live() functionality.

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

How to fix: Download the jquery migrate plugin and add it to your bundling:

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

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

Update: The migrate plugin is now available from Nuget as well:

PM>安装,包装jQuery.Migrate

PM> Install-Package jQuery.Migrate

这篇关于ASP.NET MVC 4 jQuery验证脚本包不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆