Подтвердить что ты не робот

ASP.NET MVC 4 jQuery Validation Script Не работает пакет

Недавно я обновил сайт для использования 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>

Может кто-нибудь указать, почему эта ошибка может возникнуть?

Спасибо, Алекс.

4b9b3361

Ответ 1

Метод .live устарел в jQuery v1.7 + и удален в jQuery v1.9 +.

Bugreport: http://bugs.jquery.com/ticket/13213
Объяснение: http://jquery.com/upgrade-guide/1.9/#live-removed

.live() удален

Метод .live() устарел после jQuery 1.7 и был удалено в 1.9. Мы рекомендуем обновить код для использования метода .on() вместо. Чтобы точно соответствовать $( "a.foo" ). Live ("click", fn), например, вы можете написать $(document).on("click", "a.foo", fn). Для большего информацию см. в документации .on(). Тем временем jQuery Migrate plugin можно использовать для восстановления функциональности .live().

Как исправить: Загрузите плагин jquery migrate и добавьте его в свой комплект:

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

Обновление: плагин migrate теперь доступен и от Nuget:

PM > Установить пакет jQuery.Migrate