I am abviously missing something, but I keep getting this message when trying to add auto complete to a text box: .autocomplete is not a function
_Layout (Only the head section):
<head>
<meta charset="utf-8" />
<title>@ViewBag.Title - My ASP.NET MVC Application</title>
<link href="~/favicon.ico" rel="shortcut icon" type="image/x-icon" />
<meta name="viewport" content="width=device-width" />
<link href="../../Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />
<script src="../../Scripts/jquery-1.6.2.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
@Styles.Render("~/Content/themes/base/css", "~/Content/css")
@Scripts.Render("~/bundles/modernizr")
Index:
<script type="text/javascript">
$(function () {
$("#searchTerm").autocomplete({
source: "/Search/AutocompleteSuggestions",
minLength: 3,
select: function (event, ui) {
if (ui.item) {
$("#searchTerm").val(ui.item.value);
$("form").submit();
}
}
});
});
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))'
{
<input id="searchTerm" name="searchTerm" type="text" />
<input type="submit" value="Go" />
}
I am pretty sure that the Jquery plugin is not loading correctly but I can’t see why!
After scratching my head for an hour or so I found the problem, so here goes:
@Scripts.Render(“~/bundles/jqueryval”)
@Scripts.Render(“~/bundles/jqueryui”)
MVC4 ships with the correct JQuery files and the default configuration already includes the necessary packages.
Hope this helps someone else.