I'm working on ASP.Net App and I have a simple view model with a List property as:
public List<int> SelectedStations { get; set; } = new List<int>();
Then via javascript I populate an array as:
var stations=[];
stations.push({
StationId:grid.dataItem(this).StationId,
});
So If I debug this it return data as following:
So it works, now I have an Ajax call to send this view model to controller as:
var data = {
...
SelectedStations: stations
}
$.ajax({
url:'/Test/Create/',
data: AddAntiForgeryToken({ model: data }),
method: 'POST',
success: function(){
setTimeout(function() {
location.reload();
}, 1000);
},
});
But the controller is always receiving list as empty list, what am I doing wrong?
console.log(data) result before send to ajax:
Controller receive it as:



public async Task<IActionResult> Create(MyViewModel model), I'm sure the model it is working because I have more properties in and I'm receiving the correct data, but that list is always empty @hijinxbassistconsole.log(data)show before doing the ajax call?[5, 6], it's an array of objects[{StationId: 5}, {StationId: 6}]. Either adapt the mapping on the controller or before the ajax call.