How to transfer data dynamicwhen calling AJAXto MVC Controller?
Controller:
public JsonResult ApplyFilters(dynamic filters){
return null;
}
Call AJAX:
$(':checkbox').click(function (event) {
var serviceIds = $('input[type="checkbox"]:checked').map(function () {
return $(this).val();
}).toArray();
$.ajax({
type: 'GET',
url: '/home/ApplyFilters',
data: JSON.stringify({
name: serviceIds
}),
contentType: 'application/json',
success: function (data) {
alert("succeeded");
},
error: function (err, data) {
alert("Error " + err.responseText);
}
});
});
Ideally, it would be what filterswould contain serviceIdsas a property
For example, for example filters.ServiceIds. I have another filter for a range of dates, and it will be added as follows: filters.DateRange.
And the server side receives the filter as an object dynamicinApplyFilters()
source
share