對象到控制器的陣列我的數組是這樣的:傳遞使用JSON
Array[2]
0: Object
StockNo: "1"
InvoiceNo: "1234"
MaterialName: "MaterialName1"
PONo: "1234"
PRNo: "2124"
Project: "ProjectName"
Qty: "1"
Remarks: "Test"
Supplier: "SupplierName"
TotalAmount: "23"
Type: "2"
Unit: "23"
1: Object
StockNo: "2"
InvoiceNo: "1234"
MaterialName: "MaterialName2"
PONo: "1234"
PRNo: "2124"
Project: "ProjectName2"
Qty: "1"
Remarks: "Test"
Supplier: "SupplierName"
TotalAmount: "23"
Type: "2"
Unit: "23"
這2陣列是在一個名爲「inventoryList」 變量裏面,我想這在我的控制器通過。我用
JSON.stringify(inventoryList)
,但它不工作。
這裏是我的腳本:
function addSomething() {
var dateReceived = $('#DateReceived').val();
$.ajax({
url: "/MyController/Create",
type: 'post',
dataType: 'json',
async: false,
data: {
'dateReceived': dateReceived,
'rrList': JSON.stringify(inventoryList)
},
success: function (data) {
if (data.errorMessage != '') {
alert(data.errorMessage);
}
else {
window.location.href = '/MyController/Index';
}
}
})
}
$ _ POST var爲空或有什麼? – Daimos
@Daimos,你確定你在談論asp.net-mvc-5,因爲它標有標籤嗎? – Alex
@Diamos它不是PHP .. –