【问题标题】:Object doesn't support property or method 'autocomplete'对象不支持属性或方法“自动完成”
【发布时间】:2016-09-13 05:19:48
【问题描述】:
@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);
}

【问题讨论】:

  • 需要在列表值和标签中返回两个属性。
  • 您有 2 个 jquery-ui 副本,应该删除一个。

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


【解决方案1】:

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

这是包含文件的顺序

  1. jQuery.js
  2. jQuery UI.js
  3. autocomplete.js

在自动完成之前添加以下内容

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

【讨论】:

  • 我想我添加了很多不需要的脚本兄弟
  • 是的,您正在添加 2 个 jquery-ui 副本。删除一个
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-08-10
  • 1970-01-01
  • 2019-07-05
  • 2015-04-14
  • 2020-09-03
  • 2015-04-09
相关资源
最近更新 更多