Microsoft JScript运行时错误:对象不支持属性或方法'live'?

时间:2013-02-08 14:33:14

标签: jquery asp.net-mvc-3

我点击了按钮,显示以下错误“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>
}

3 个答案:

答案 0 :(得分:15)

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

1)恢复到旧版本的jquery。

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

3)放回jquery-latest。

答案 1 :(得分:6)

您还可以查看包含jQuery Migrate以帮助升级到jQuery 1.9

答案 2 :(得分:2)

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

问题是这个错误在jquery.unobtrusive-ajax.js内被抛出,你在@Scripts.Render("~/bundles/jqueryval")

中作为捆绑包的一部分包含在内

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