asp.net mvc 3 - jquery autocomplete using mvc3 dropdownlist -
i using asp.net mvc3 ef code first. have not worked jquery. add autocomplete capability dropdownlist bound model. dropdownlist stores id, , displays value.
so, how wire jquery ui auto complete widget display value user typing store id?
i need multiple auto complete dropdowns in 1 view too.
i saw plugin: http://harvesthq.github.com/chosen/ not sure want add more "stuff" project. there way jquery ui?
update
i posted sample project showcasing jqueryui autocomplete on textbox @ github https://github.com/alfalfastrange/jqueryautocompletesample
i use regular mvc textbox like
@html.textboxfor(model => model.mainbranch, new {id = "searchfield", @class = "ui-widget textfield_220" })
here's clip of ajax call
it checks internal cached item being searched for, if not found fires off ajax request controller action retrieve matching records
$("#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 isn't code should able see here how cache search, , ajax call made, , done response. have select
section can selected value
Comments
Post a Comment