Skip to content

Instantly share code, notes, and snippets.

@venblee
Last active December 19, 2015 00:29
Show Gist options
  • Save venblee/5868758 to your computer and use it in GitHub Desktop.
Save venblee/5868758 to your computer and use it in GitHub Desktop.
Using Select Viewmodel to preload and AJAX for calls
$('#PostalCitySelect').select2({
initSelection: function(element, callback) {
var data = { id: $("#Supplier.PostalCityId").attr("value"), text: $("#Supplier_PostalCity_City").attr("value") };
callback(data);
@* $.ajax('@Url.Action("SearchCityById", "Suppliers")', {
data: {
searchTerm: $("#Supplier_PostalCity_CityId").attr("value")
},
dataType: "json"
}).done(function (data) { alert(data), callback(data); });
*@
},
placeholder: 'Select an City',
minimumInputLength: 4,
ajax: {
url: '@Url.Action("SearchCity", "Suppliers")',
dataType: 'json',
data: function(term, page) {
return {
searchTerm: term
};
},
results: function(data, page) {
return { results: data };
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment