对象不支持属性或方法'自动完成'

时间:2016-05-17 08:07:48

标签: javascript c# jquery asp.net-mvc jquery-ui

@model IEnumerable<ModelClass.DhoniRegistry>
@using (@Html.BeginForm())
{
    <b> Dhoni Name  </b>
    @Html.TextBox("SearchTerm", null, new { id = "txtSearch" })
    <input type="submit" value="Search" />
}    

<link href="~/Content/jquery-ui.min.css" rel="stylesheet" />
<link href="~/Content/jquery-ui.structure.min.css" rel="stylesheet" />
<link href="~/Content/jquery-ui.theme.min.css" rel="stylesheet" />
<script src="~/Scripts/external/jquery/jquery.js"></script>
<script src="~/Scripts/jquery-ui.min.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script type="text/javascript">
    $(function ()
    {
        $("#txtSearch").autocomplete({ source: '@Url.Action("ASDhoniName")' });
    });
</script>

控制器

public JsonResult ASDhoniName(string SearchTerm)
{
    DhoniRegistryBusinessSer dhoniBisSer = new DhoniRegistryBusinessSer();
    List<string> dhoniReg;
    dhoniReg = dhoniBisSer.ListDhoniRegistry().Where(x => x.DhoniName.StartsWith(SearchTerm))
        .Select(y => y.DhoniName).ToList();
    return Json(dhoniReg,JsonRequestBehavior.AllowGet);
}

1 个答案:

答案 0 :(得分:0)

您丢失/错误放置jQuery/ jQuery UI.js/ autocomplete.js个文件。 您还添加了两份jquery-ui副本。删除一个。

这是包含文件的顺序

  1. 的jquery.js
  2. jQuery UI.js
  3. autocomplete.js
  4. 在自动填充之前添加​​以下内容

    <script src="http://code.jquery.com/jquery-1.9.1.js />
    <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js" />