I'm using autocomplete in a MVC application but it won't autocomplete cause it can't find the function. I did however include the jquery-ui like this:
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title Smoelenboek</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
@Scripts.Render("~/Scripts/jquery-2.1.1.js")
@Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.js")
@Scripts.Render("~/Scripts/jquery-ui-1.11.2.min.js")
</head>
however when i run the code like this:
@Html.TextBox("parameter")
<script type="text/javascript">
$(document).ready(function () {
$('#parameter').autocomplete({
source: '@Url.Action("Autocomplete", "Person")'
});
})
</script>
it won't get to the method i've defined there here's the code for that method:
[HttpPost]
public ActionResult Autocomplete(string term)
{
var items = new[] { "Apple", "Pear", "Banana", "Pineapple", "Peach" };
var filteredItems = items.Where(
item => item.IndexOf(term, StringComparison.InvariantCultureIgnoreCase) >= 0
);
return Json(filteredItems, JsonRequestBehavior.AllowGet);
}
it's just testdata but i don't get why it won't work. Perhaps duplicate imports or something?