2013-01-16 42 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()的結果() –