【问题标题】:JQuery autocomplete and MVC no suggestionsJQuery 自动完成和 MVC 没有建议
【发布时间】:2014-09-21 17:59:04
【问题描述】:

我在使用 JQuery 自动完成文本时遇到问题。我使用了 ChromeBug,一切看起来都很好。文本正在发送到控制器,我在那里设置断点以查看他得到的内容,并且一切看起来都很好。 但在文本框中我没有任何建议。

我的控制器看起来像这样:

public JsonResult AutocompleteTowns(string term) {
            return this.Json(db.Miastoes.Where(x => x.Nazwa.StartsWith(term)).ToString(), JsonRequestBehavior.AllowGet);
        }

脚本:

    $(document).ready(function () {
        $('#nazwaMiasta').autocomplete({
            source: '@Url.Action("AutocompleteTowns", "Administrator")'
        });
)};

你有什么想法吗?

【问题讨论】:

    标签: asp.net-mvc jquery-autocomplete


    【解决方案1】:

    问题解决了! 我没有返回字符串,我返回的是 Miastoes 类型的对象。

      public JsonResult AutocompleteTowns(string term) {
                var city = from c in db.Miastoes
                           where c.Nazwa.StartsWith(term)
                           select c.Nazwa;
                return this.Json(city, JsonRequestBehavior.AllowGet);
            }
    

    【讨论】:

      猜你喜欢
      • 2011-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-19
      相关资源
      最近更新 更多