My goal is to send my JSON list back to the POST method (EditCompanyReportField) on the C# server side. The related parameter (fieldSorted) in my method is an array object, but the values are not being passed through. I have a few question marks regarding this.
Is KeyValuePair a struct and not a primitive type? Is that why?
Do I need to serialize the JSON object?
Also, I prefer not to create a model class for it.
Here is the back-end method:
public void EditCompanyReportField(IEnumerable<KeyValuePair<int, int>> fieldSorted)
Client-side JavaScript code:
var fieldSorted= [];
for (var i = 0; i < $scope.reportfield.length; i++) {
fieldSorted.push({ Key: $scope.reportmapfield[i].MappedFieldId,
Value: $scope.reportmapfield[i].IndexNo = i + 1 });
};
$http({
method: 'post', url: '/mapped/editcompanyreportfield',
data: { fieldSorted: fieldSorted }
}).success(function () {
$state.go("list-report");
toastr.success(infoMessage.success);
});
The fieldSorted parameter on the back-end shows:
[0] {[0,0]}
[1] {[0,0]}
[2] {[0,0]}
Thank you in advance...