asp.net mvc 3 - url.action for auto-complete -
after reply changed code to
@html.textboxfor(per => per.hospital, new { style = "width:220px", @maxlength = "50", data_autocomplete = url.action("hospitallist", "person") })
my jquery
$(document).ready(function () { $('input[data_autocomplete]').each(function () { var url = $(this).data('autocomplete'); $(this).autocomplete({ source: function (request, response) { $.getjson(url, { term: request.term }, response); } }); }); });
and created new action result
public actionresult hospitallist(string term) { list<string> result = new list<string>(); result.add("hospital 1"); result.add("nyumc"); result.add("christ"); result.add("bellevue"); result.add("newyork-presbyterian"); result.add("north central bronx hospital"); return json(result , jsonrequestbehavior.allowget); }
now going wromg. see a text box , no behavior of auto complete. should including jquery library work
you haven't shown autocomplete plugin using. if jquery ui autocomplete
return filtered results json controller action:
[httpget] public actionresult personsearch(string term) { // term parameter contain value entered user in textbox. // here use , query database in order filter results. string[] result = new string[] { "filtered value 1", "filtered value 2", "filtered value 3", "filtered value 4", }; return json(result, jsonrequestbehavior.allowget); }
and attach plugin:
$(function() { $('input[data-autocomplete]').each(function() { var url = $(this).data('autocomplete'); $(this).autocomplete({ source: function(request, response) { $.getjson(url, { term: request.term }, response); } }); }); });
notice how controller action takes term
parameter , should return list of strings json.
Comments
Post a Comment