- Tutorial I am following
Hi, I am implementing jquery autocomplete using this tutorial ASP.NET Tutorial Part 76 Implement autocomplete textbox functionality in mvc https://www.youtube.com/watch?v=MmBdMZJ3Jlo
- Problem
When I type something in input box, autocomplete does not work
- Description
I have implemented the search functionality and its working fine but i am stuck on autocomplete function of jquery. I have searched a lot on google and stack overflow previous questions, i tried everything but couldn't solve my problem.
- Code
Here is my code of autocomplete ( i have not included code of searching )
Index.cshtml
<link href="~/Content/jquery-ui.css" rel="stylesheet" type="text/css" />
<link href="~/Content/jquery-ui.min.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/jquery-2.1.4.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-ui.js" type="text/javascript"></script>
<script src="~/Scripts/jquery-ui.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#txtSearch").autocomplete({
source: '@Url.Action("GetAirports")'
});
});
</script>
@using(@Html.BeginForm())
{
<br />
<b>AirPort Code:</b>
@Html.TextBox("SearchTerm", null, new { id="txtSearch"})
<input type="submit" value="Search" />
}
and my controller code
HomeController.cs
public JsonResult GetAirports(string term)
{
traveloticketEntities db = new traveloticketEntities();
List<String> Airports = new List<String>();
Airports = db.IataAirportCodes.Where(x => x.code.StartsWith(term)).Select(y=>y.code).ToList();
return Json(Airports, JsonRequestBehavior.AllowGet);
}
jquery-ui.jsandjquery-ui.min.j. Don't do that. Reference the unminified one during development, and the minified one on production.