jquery - select2 with ajax MVC does not hit results option -
i using select2
autocomplete
, select multiple options. below how initialize
select2
$(".selectpickerphone").select2({ allowclear: true, minimuminputlength: 2, ajax: { cache: false, datatype: "json", type: "get", url: "@url.action("getcontactnumbers ", "hmcontroller")", data: function(searchterm) { return searchterm; }, results: function(data) { debugger; if (data.isuser) { return; } return { results: $.map([data], function(item) { return { text: item.name, id: item.phonenum, data: item } }) }; } }, formatresult: function(response) { data = response.data; console.log(data); this.description = '<div id="fmu_select2_ajax_result">' + "<div>nom du produit : " + data.name + "</div>" + "<div>" + "<div>" + data.phonenum+ "</div>" + "</div>" + '</div>'; return this.description; }, formatselection: function(response) { data = response.data; return data.phonenum+ " - " + data.name; }, escapemarkup: function(m) { return m; }, dropdowncssclass: "bigdrop" });
below jsonresult
- actionmethod
[httpget] public jsonresult getcontactnumbers(string term) { using (_db = new context()) { _adrep = new adrp(); var contactlist = _adrep.fetchcustomeruserphone(_db,term); return json(contactlist, jsonrequestbehavior.allowget); } }
and below response when viewed in network tab.
[{"name":"guruprasad rao","isuser":true,"phonenum":"8495000049"}, {"name":"guruprasad rao","isuser":false,"phonenum":"8495000050"}, {"name":"test","isuser":false,"phonenum":"8495000051"}]
but no matter what, debugger i've placed in results
option of ajax
not hit , data not displayed. how receive response , display it?
update
i using select2 v4.0.1
i tried bind in asp.net mvc 5.
i used web services ,controller http post method, web api 2 not use in call event of select2 .
use asp.net generic handler
produce callback result try bind select2.
Comments
Post a Comment