Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I am trying to load options for select2 from a list.
Here is what I have done so far:
View
----
<input type="hidden" id="myInput" multiple="multiple" />


Js file
-------
$("#myInput").select2({
  placeholder: "select from the following",
  ajax:
  {
     url:http://debug:10482/myData/GetList",
     dataType: "jsonp",
     data: function (term, page) {
       return {
        q: term,
        page_limit: 10,
        apikey: "ju6z9mjyajq2djue3gbvv26t"
       };
     },
     results: function (data, page) {
       return { results: data}
     }
  }
});


myData.cs
---------
public jsonResult GetList(string q)
{
   List<string> myList = new List<string>() {"one, "two", "three"};
   return Json(myList);
}


I can see in debug it enters the "GetList" function but can't see any
results found in the select2 input.
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900