2013-01-16 11 views
29

最近、ASP.NET MVC 4を使用するようにWebサイトをアップグレードし、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") 
01ここで

は私のレンダリングされた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> 

このエラーが発生する理由を誰かが指摘することはできますか?

ありがとう、 アレックス。

+0

バンドル/ jqueryが最初にレンダリングされるかどうかを確認しましたか?ライブラリの前にロードされていることを確認してください。 –

+0

レンダリングされたHTMLを質問に追加しました。そこに何かが見えますか? –

答えて

49

.liveメソッドは、jQuery v1.7以降で非推奨となり、jQuery v1.9以降では削除されました。

バグレポート:http://bugs.jquery.com/ticket/13213
説明:使用できるようになりました移行プラグイン: jquery migrate pluginをダウンロードして、あなたのバンドルに追加:

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

アップデート修正方法 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.

Nugetも同様:

PM> Install-Package jQuery.Migrate

+0

ああ、それはそれがそこにあるべきではないことを認識していなかったということです。しかし、私は別のエラー(質問に追加)を取得している可能性がありますあなたはおそらく私もそれを引き起こしている教えてください? –

+0

回答が更新されました。 –

+0

手動で追加されていないものは、Scripts.Render()の結果です –

関連する問題