I am using Select2 for a list of items which i populate from the MVC Model on the page load (which are options that i have dealt with before) but when I add my AJAX call and MinimumInputLength = 7 it hides the options from the model and I can only search for them or new items using my ajax call, is there a way i can show the prepopulated ones from the model and also search using my ajax call but if i do not input anything in the searchbox it shows me the prepopulated ones?
@Html.DropDownListFor(model => model.LinkedItems[i].ItemId, new SelectList(Model.GetItems, "Value", "Text", Model.LinkedItems[i].ItemId), "Item Name", new { @class = "form-select item-select-2" })
$('.item-select-2').select2({
language: {
errorLoading: function () {
return "No itemfound.";
}
},
width: 'resolve',
theme: 'bootstrap-5',
minimumInputLength: 7,
ajax: {
url: '/get-items',
async: true,
delay: 250,
dataType: 'json',
data: function (params) {
return {
q: params.term
};
},
processResults: function (data) {
return {
results: $.map(data.Results, function (item) {
return {
id: item.Id,
text: item.Text
};
})
};
}
}
});