There are many examples of AutoComplete funcionality on the internet like this one bellow
This is a typical method of a controler
public JsonResult AutoCompleteSuggestions(string searchstring)
{
var suggestions = (new TerritoriesDAO()).getTerritoryDescription(term);
var namelist = suggestions.Where(n => n.ToLower().StartsWith(term.ToLower()));
return Json(namelist, JsonRequestBehavior.AllowGet);
}
Problem is: when the method is called by the view, search string always comes null.
Debugging on firefox you're gona find out that the parameter name is term. So, if you name it as searchstring, it will always be null. Why this happens? I have no idea.
--
[16:21:27.306] GET http://localhost:3289/Territories/AutocompleteSuggestions?term=w [HTTP/1.1 200 OK 0 ms]
--
Change the parameter name to term and magically the value will appear!
public JsonResult AutoCompleteSuggestions(string term)
{
var suggestions = (new TerritoriesDAO()).getTerritoryDescription(term);
var namelist = suggestions.Where(n => n.ToLower().StartsWith(term.ToLower()));
return Json(namelist, JsonRequestBehavior.AllowGet);
}
Nenhum comentário:
Postar um comentário