I am trying to post an object which has some properties and arrays in it.
Properties are submitted just fine, but arrays within object are not serialized back in a MVC.NET Controller.
In this example page is mapped properly, but array object (locations) is always null in the controller.
Any suggestions?
//add some data
$scope.formData = {
Page: 1,
Locations: []
};
$scope.formData.Locations.push({
LocationID: 1,
LocationType: 1
});
$scope.formData.Locations.push({
LocationID: 2,
LocationType: 2
});
//post method
$http({
method: 'POST',
url: 'myurl',
params: $scope.formData,
}).then(function successCallback(
response) {
//do something
}, function errorCallback(response) {
//do something
});
Serverside model
public class SearchAuctionData
{
public int Page { get; set; }
public List<SmallLocation> Locations { get; set; }
}
public class SmallLocation
{
public short LocationID { get; set; }
public short LocationType { get; set; }
}
Controller
[HttpPost]
[AllowAnonymous]
public async Task<JsonResult> GetAuctions(SearchAuctionData data)
{
//do somethng
return Json(result);
}