2014-09-21 42 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); 
     }