I'm having trouble filling out a combobox with Select2
I have my JS:
$("#comboplatos").select2({
placeholder: "Type to select a sponsor",
minimumInputLength: 3,
allowClear: true,
style: "display: inline-block",
width: 400,
ajax: {
cache: false,
dataType: 'json',
type: "GET",
url: "/Admin/LlenarDestinoconJSON",
data: function (params) {
return {
query: params.term,
page: params.page// search term
};
},
results: function (data) {
return { results: data };
}
},
formatResult: contractFormatResult,
formatSelection: contractFormatSelection,
escapeMarkup: function (m) { return m; }
});
And my controller is:
public JsonResult LlenarDestinoconJSON(string query)
{
var lista = CMM_PersonaNeg.Instancia.Listar(query);
var JSonLista = Json(lista.ToList(), JsonRequestBehavior.AllowGet);
return JSonLista;
}
When executing the application, through the debug I can get the data I want, but it does not show me anything in the combo and this error appears in console:
select2.js: 4008 Uncaught TypeError: Can not read property 'slice' of undefined
I have no idea how to solve it, look in several forums but I did not find any solution that could help me.
I hope you can tell me if something is wrong with my code or if something is missing.
Thank you very much.