How can I pass dynamic data with an AJAX call to an MVC Controller?
Controller:
public JsonResult ApplyFilters(dynamic filters){
return null;
}
The AJAX call:
$(':checkbox').click(function (event) {
var serviceIds = $('input[type="checkbox"]:checked').map(function () {
return $(this).val();
}).toArray();
//alert(serviceIds);
$.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);
}
});
//return false;
});
Ideally would be that the filters would contain the serviceIds as a property
For example like this: filters.ServiceIds.
I got another filter for a date range and that one would be added like so: filters.DateRange.
And server side get the filter as a dynamic object in the ApplyFilters()
dynamicobjects are evaluated at the run time so change the return toreturn Json(filters)so that you can see the actual data returned in the response.objectis. But that's failing because some how the data isn't passed 'good'.