mvc4 autocomplete with more options

79 Views Asked by At

I have the jquery autocomplete UI working great but i was wondering if on the list of options i can put more than 1 autocomplete option. To clear this up I have a textbox that looks up location but currently when a user types something in it only shows the cities such as "dallas" instead of "dallas, Tx" how can I get it like this? http://www.trulia.com/ this website has it perfectly. This is my code

public ActionResult autocomplete(string term)
    {
        var zipps = db.zipss.Where(s => s.city.StartsWith(term)).Take(10).Select(r => new { label = r.city, r.state }).ToList();
 return Json(zipps,JsonRequestBehavior.AllowGet);

    }
1

There are 1 best solutions below

0
On

you can add multiple return values like this

return Json(new { zipps = zipps, Success = true, JsonRequestBehavior.AllowGet});

you can add as many options as you want here