2014-09-21 43 views
-1

我有自动完成文本的JQuery.I使用ChromeBug的问题,一切都很好。文本发送到控制器,我把断点看看他得到什么东西看起来很好。 但在文本框中,我没有任何建议。JQuery自动完成和MVC没有建议

我CONTROLER看起来像这样:

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

SCRIPT:

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

你有什么想法有什么不对?

回答

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