I am trying to create search box which show results when user is typing in.
I have the following in my partial view:
@Html.EditorFor(m => m.CategoryName, new { htmlAttributes = new { @id = "inputCat", @class = "form-control", @placeholder = "Enter category name...", @spellcheck = "true" } })
In my main view where I load the partial view I have:
$('#inputCat').autocomplete({
source: 'Editor/SearchCategory'
});
Here is my controller action:
public ActionResult SearchCategory(string term)
{
ApplicationDbContext db = new ApplicationDbContext();
return Json(db.Categories.Where(cat => cat.CategoryName.StartsWith(term)), JsonRequestBehavior.AllowGet);
}
When I type in the input field in the browser console I get this error:
GET http://localhost:port/Editor/SearchCategory?term=s 500 (Internal Server Error)
I cannot understand where is the problem. Any help will be appreciated. Thanks in advance.