Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
All-Star
18647 Points
2647 Posts
Apr 16, 2012 03:28 PM|LINK
To get the dynamic list from your model you can do two things. You can either have the model write the javascript array for you, so in your view you would write server side code @... that writes out javascript.
Another option is to have the autocomplete pull the data from an action method via ajax. http://jqueryui.com/demos/autocomplete/#remote
Something like:
//js $( "#birds" ).autocomplete({ source: "/Home/AutoComplete", minLength: 2, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.id : "Nothing selected, input was " + this.value ); } }); // Controller public ActionResult AutoComplete(string q){ var data = //get from db where q = whatever return Json(data,JsonRequestBehavior.AllowGet); }
CodeHobo
All-Star
18647 Points
2647 Posts
Re: Autocomplete question
Apr 16, 2012 03:28 PM|LINK
To get the dynamic list from your model you can do two things. You can either have the model write the javascript array for you, so in your view you would write server side code @... that writes out javascript.
Another option is to have the autocomplete pull the data from an action method via ajax.
http://jqueryui.com/demos/autocomplete/#remote
Something like:
//js $( "#birds" ).autocomplete({ source: "/Home/AutoComplete", minLength: 2, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.value + " aka " + ui.item.id : "Nothing selected, input was " + this.value ); } }); // Controller public ActionResult AutoComplete(string q){ var data = //get from db where q = whatever return Json(data,JsonRequestBehavior.AllowGet); }Blog | Twitter : @Hattan