Update
I just posted a sample project demonstrating jQueryUI autocomplete in a text box on GitHub https://github.com/alfalfastrange/jQueryAutocompleteSample
I use it with regular MVC TextBox like
@Html.TextBoxFor(model => model.MainBranch, new {id = "SearchField", @class = "ui-widget TextField_220" })
Here's a clip of my Ajax call
First, it checks its internal cached file to find the element, if it does not find that it disables the Ajax request for my controller action to get comparable entries
$("#SearchField").autocomplete({ source: function (request, response) { var term = request.term; if (term in entityCache) { response(entityCache[term]); return; } if (entitiesXhr != null) { entitiesXhr.abort(); } $.ajax({ url: actionUrl, data: request, type: "GET", contentType: "application/json; charset=utf-8", timeout: 10000, dataType: "json", success: function (data) { entityCache[term] = term; response($.map(data, function (item) { return { label: item.SchoolName, value: item.EntityName, id: item.EntityID, code: item.EntityCode }; })); } }); }, minLength: 3, select: function (event, result) { var id = result.item.id; var code = result.item.code; getEntityXhr(id, code); } });
This is not all the code, but you can see here how the cache is searched, then the Ajax call is made, and then what is done with the answer. I have a select
section, so I can do something with the selected value
source share