Вот мой javascript метод:
this.ingressoMerce = function () {
operationLogs = new Array();
ordersToUpdate = new Array();
$('.position-checkb').each(function (index, obj) {
if (this.checked === true) {
let positionNumber = $(this).parent().parent().find('td:eq(1)').text();
let qtaRicevute = $(this).parent().parent().find(".qta-ricevute-txt").val();
let qtaOrdine = $(this).parent().parent().find('td:eq(5)').text();
let qtaGiaRicevute = $(this).parent().parent().find('td:eq(7)').text();
if (parseInt(qtaOrdine) > 0 && (parseInt(qtaRicevute) + parseInt(qtaGiaRicevute) <= parseInt(qtaOrdine))) {
var orderToUpdate = Utils.getAllData().toJSON().find(x => x.Posizione == positionNumber);
orderToUpdate.ReceivedQty = parseInt(qtaRicevute);
ordersToUpdate.push(orderToUpdate);
$(this).parent().parent().find('td:eq(7)').text(qtaRicevute);
let operationName = "Ingresso merce";
let operationLog = {};
operationLog.OperationQty = qtaRicevute;
operationLog.OperationDate = new Date();
operationLog.OrderDetailOperationTypeRelations = ['Ingresso merce'];
operationLogs.push(operationLog);
} else {
alert("La quantità inserita supererebbe la quantità totale dell'ordine, ricontrollare")
}
}
});
console.log('Orders to update', ordersToUpdate);
console.log('Logs', operationLogs);
$.ajax({
type: "POST",
traditional: true,
url: updateOrderDetailUrl,
content: "application/json;",
data: { ordersToUpdate: ordersToUpdate },
}).done(function () {
alert('ok fatto, chiamare log');
});
}
А вот метод, который вызывается в контроллере:
[HttpPut("/UpdateOrderDetails")]
public async Task UpdateOrderDetails(List<Contracts.OrderDetail> ordersToUpdate)
{
await orderService.UpdateOrderDetails(ordersToUpdate);
}
Проблема в том, что массив при поступлении в контроллер имеет число = 0. Вместо этого в javascript код заполняется. Я не могу понять, где я ошибаюсь.