.autocomplete不是MVC4的功能

时间:2012-09-04 15:54:53

标签: javascript razor asp.net-mvc-4

_Layout.cshtml

<script src = "@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
   <script src = "@Url.Content("~/Scripts/jquery-ui-1.8.23.custom.min.js")" type="text/javascript"></script>
   <link href="@Url.Content("~/Content/smoothness/jquery-ui-1.8.23.custom.css")" rel="stylesheet" type="text/css" />

我的模特

@using (Html.BeginForm()){<fieldset>
    <legend>Person Search</legend>

    <div class="editor-label">
        @Html.LabelFor(model => model.Name)
    </div>
    <div class="editor-field">
        @Html.EditorFor(model => model.Name)
    </div>
    <p>
         <input type="submit" value="Search" />
        @*@ko.Html.Button("Search", "SearchPerson", "Person")*@
    </p>

}

视图中的脚本

 <script src = "@Url.Content("~/Scripts/jquery.autocomplete.js")" type="text/javascript"></script>

 <script type="text/javascript">
 $(document).ready(function () {
     $("#Name").autocomplete('@Url.Action("PersonNameAutocomplete", "Person")', { minChars: 3 });
});

错误是TypeError:$(“#Name”)。自动完成不是函数

1 个答案:

答案 0 :(得分:0)

我解决了错误并将脚本放在另一个区域,所以

 @section Scripts 
 {
     @Scripts.Render("~/bundles/jqueryval")
     <script src = "@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
     <script src = "@Url.Content("~/Scripts/jquery-ui-1.8.23.custom.min.js")" type="text/javascript"></script>
     <link href="@Url.Content("~/Content/smoothness/jquery-ui-1.8.23.custom.css")" rel="stylesheet" type="text/css" />
 }