2013-01-16 32 views
29

我已经最近升级了一个网站使用ASP.NET MVC 4,并有以下代码来呈现我的jQuery验证包。在文本框中单击时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> 

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

谢谢, Alex。

+0

做了检查bundle/jquery是否第一次呈现?确保它在任何库之前加载 –

+0

将已呈现的HTML添加到问题中,您能看到任何内容吗? –

回答

49

.live方法已在jQuery v1.7 +中弃用,并在jQuery v1.9 +中删除。

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

.live() removed

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 migrate plugin并将其添加到您的捆绑:

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

更新:迁移插件现在可以来自Nuget:

PM> Install-Package jQuery.Migrate

+0

啊,它补充说,并不知道它不应该在那里。但是,我收到另一个错误(添加到问题),你能告诉我是什么原因造成的吗? –

+0

答复已更新。 –

+0

O没有被手动添加,这是Scripts.Render()的结果() –