8

我单击按钮时显示以下错误“Microsoft JScript 运行时错误:对象不支持属性或方法'live'” 我的视图页面如下:

@model Charis.Models.Products
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<link href="../../Content/CharisSite.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
@using (Html.BeginForm("Create", "Prod", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)
    <table><tr><td>
    <table>
    <tr>
    <td>
     <fieldset>
             <legend>Products</legend>

     <table>
        <tr>
        <td>
            <div class="editor-label">
            @Html.LabelFor(model => model.Productname)
            </div>
        </td>
        <td>
             <div class="editor-field">
            @Html.EditorFor(model => model.Productname)
            @Html.ValidationMessageFor(model => model.Productname)
            </div>
        </td>
        </tr>
        <tr>
        <td>
            <div class="editor-label">
                @Html.LabelFor(model => model.ProductPrice)
            </div>
        </td>
        <td>
            <div class="editor-field">
            @Html.EditorFor(model => model.ProductPrice)
            @Html.ValidationMessageFor(model => model.ProductPrice)
            </div>
        </td>
        </tr>
        <tr>
        <td>
            <div class="editor-label">
            @Html.LabelFor(model => model.ProductDiscount)
            </div>
        </td>
        <td>
            <div class="editor-field">
            @Html.EditorFor(model => model.ProductDiscount)
            @Html.ValidationMessageFor(model => model.ProductDiscount)
            </div>
        </td>
        </tr>

        <tr>
        <td>
            <div class="editor-label">
                @Html.LabelFor(model => model.LanguageType)
            </div>
        </td>
        <td>
             <div class="editor-field">
            @Html.EditorFor(model => model.LanguageType)
            @Html.ValidationMessageFor(model => model.LanguageType)
            </div>
        </td>
        </tr>

        <tr>
        <td>
             <div class="editor-label">
                @Html.LabelFor(model => model.ReleaseDate)
            </div>
        </td>
        <td>
                <div class="editor-field">
                         @Html.EditorFor(model => model.ReleaseDate)
                         @Html.ValidationMessageFor(model => model.ReleaseDate)
                </div>
        </td>
        </tr>
        <tr>
        <td>
             <div class="editor-label">

               <label for="file">Upload Image:</label>
            </div>
        </td>
        <td>
                <div class="editor-field">
                    <input type="file" name="file" id="file"/>
               </div>
        </td>
        </tr>

     </table> 

    </fieldset>
    </td>
    <td></td></tr>
    </table>

    </td></tr>
    <tr><td>



    <table>
    <tr>
    <td>
        <fieldset>
        <legend>Details</legend>
            <table>
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.AlbumDescription1)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.AlbumDescription1)
                            @Html.ValidationMessageFor(model => model.AlbumDescription1)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.AlbumDescription2)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.AlbumDescription2)
                            @Html.ValidationMessageFor(model => model.AlbumDescription2)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Cast)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Cast)
                            @Html.ValidationMessageFor(model => model.Cast)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.DirectedBy)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.DirectedBy)
                            @Html.ValidationMessageFor(model => model.DirectedBy)
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.ProducedBy)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.ProducedBy)
                            @Html.ValidationMessageFor(model => model.ProducedBy)
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                           <label for="file">Upload Image1:</label>
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            <input type="file" name="file1" id="file1"/>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                           <label for="file">Upload Image2:</label>
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            <input type="file" name="file2" id="file2"/>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                           <label for="file">Upload Image3:</label>
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            <input type="file" name="file3" id="file3"/>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                           <label for="file">Upload Image4:</label>
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            <input type="file" name="file4" id="file4"/>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                           <label for="file">Upload Image5:</label>
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            <input type="file" name="file5" id="file5"/>
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.NoOfDisk)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.NoOfDisk)
                            @Html.ValidationMessageFor(model => model.NoOfDisk)
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Weight)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Weight)
                            @Html.ValidationMessageFor(model => model.Weight)
                        </div>
                    </td>
                </tr>

                <tr>
                    <td>
                        <div class="editor-label">
                            @Html.LabelFor(model => model.Format)
                        </div>
                    </td>
                    <td>
                        <div class="editor-field">
                            @Html.EditorFor(model => model.Format)
                            @Html.ValidationMessageFor(model => model.Format)
                        </div>
                    </td>
                </tr>

            </table>
        </fieldset>
    </td>
    </tr>
    </table>



    </td></tr>

    <tr><td>
        <table><tr><td><fieldset><table>
            <tr>
                <td>
                <p>
                    <input type="submit" value="Create" />
                    <input type="button" value="Clear" id="btnClear" />
                </p>
                </td>
            </tr>
        </table></fieldset></td></tr></table>

    </td></tr>

    </table>

}

@*<div>
    @Html.ActionLink("Back to List", "Index")
</div>
*@
@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

@if (TempData["notice"] != null) 
{
<p style="color:Red;" >@TempData["notice"]</p>
}
4

3 回答 3

15

您正在使用 jquery latest (1.9...),其中$(sel).live(...)已被弃用,因此您的错误消息。

1) 恢复到旧版本的 jquery。

2)更新你的代码(用on替换live)。

3)放回jquery-latest。

于 2013-02-08T14:39:33.050 回答
6

您还可以考虑包含 jQuery Migrate 以帮助升级到 jQuery 1.9

于 2013-02-08T18:25:47.407 回答
2

我自己更新到 jQuery 1.9 后才遇到这个问题。但是,我注意到之前没有任何用户(除了 AliRıza Adıyahşi 在没有解释的链接中)指出您的代码的哪一部分导致了错误。毕竟,如果 $(sel).live(...)被弃用,$(sel).on(...)那么它是一个非常简单的修复,对吧?

问题是这个错误被抛出内部jquery.unobtrusive-ajax.js,您将其作为捆绑包的一部分包含在@Scripts.Render("~/bundles/jqueryval")

由于您没有使用 Ajax 表单或取消,因此该错误不太可能影响任何事情(它对我没有影响),但我无法从 Microsoft 找到任何修复程序。不幸的是,修复是进入并修复您的 jquery.unobtrusive-ajax.js 版本,替换对 .on() 的 .live 调用,直到 MS 修复官方版本。

于 2013-04-19T20:38:18.307 回答