I'm trying to send an array from AJAX POST to my controller. My request:
var selected = [];
$('.unitsCheckBox:checked').each(function () {
selected.push($(this).val());
});
data = {
Units: selected
};
console.debug(data);
$.ajax(
{
url: "/PostVacancies/PostData",
type: "POST",
dataType: 'json',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
success: function (result) {
console.debug(result);
},
error: function (xhr, status, p3, p4) {
console.debug(xhr);
console.debug(status);
console.debug(p3);
console.debug(p4);
}
});
The debug shows me that there are selected units in the data variable.
My Controller:
[HttpPost]
public bool PostData(SelectedUnits Units)
{
return true;
}
The SelectedUnits method:
public class SelectedUnits
{
public List<int> Units { get; set; }
}
I set a debug point in the return to see the Units parameter data, but it is always null.
Does anyone know what I am doing wrong?