2012-09-04 71 views
0

_Layout.cshtml.autocomplete不是函數MVC4

<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 }); 
}); 

錯誤的類型錯誤:$( 「#姓名」)自動完成不是一個函數

+0

當您在瀏覽器中查看頁面的源代碼時,您的網址爲autocomplete.js獲取c正確地重新控制?你能否成功地遵循腳本? –

+0

是的,autocomplete.js成功 –

回答

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" /> 
} 
+0

繼續,並將其標記爲答案,如果你已經解決了你自己的問題 – badunk

相關問題