I have this code that does the auto complete but apparently I am doing something wrong as it not working.
This is my view:
@Html.EditorFor(model => model.city)<br />
@Html.ValidationMessageFor(model => model.city)
<script src='http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js' type="text/javascript"></script>
<script src='<%: Url.Content("~/Scripts/jQueryUI/jquery-ui-1.8.2.custom.min.js") %>'
type="text/javascript"></script>
<script type="text/javascript">
$("#city").autocomplete({
source: '<%: Url.Action("Location", "CityList") %>'
});
</script>
This is my controller:
public class LocationController : Controller
{
private pEntities db = new pEntities();
public ActionResult CityList(string city)
{
var results = from c in db.CityCodes
where c.city.StartsWith(city)
select new { label = c.city, id = c.city_id };
return Json(results.ToArray(), JsonRequestBehavior.AllowGet);
}
the first problem was Url.Action is not getting resolved inside the javascript and the second problem like Jacob said was i had to use term.
i just used below url instead of url action.
$(“#city”).autocomplete({
source: ‘Location/CityList’
});