參數即將變爲null。MVC模型從jQuery中綁定字符串數組
MVC行動
public PartialViewResult EditMultipleOrderStates(
string[] orderTypeNames,
int[] orderIds)
的JavaScript
$('#edit-mulitple-order-states-button').click(function() {
ids = [];
types = [];
$checked = $('.order-queue-order input:checked');
$orders = $checked.closest('.order-queue-order');
$orders.each(function (index, elem) {
$order = $(elem);
ids.push($order.attr("orderId"));
types.push($order.attr("orderType"));
});
data = {
orderIds: ids,
orderTypeNames: types
};
$.post('EditMultipleOrderStates', data, function (response) {
//...
});
});
提琴手
orderIds%5B%5D=97&orderIds%5B%5D=98&orderIds%5B%5D=93&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder
這是造成問題的方括號嗎?我怎樣才能綁定到這些數組?
編輯:我手動構建查詢字符串的同時。
query = "";
for each...
query += "orderIds=" + $order.attr("orderId") + "&";
query += "orderTypeNames=" + $order.attr("orderType") + "&";
使用此處發佈的解決方案。 http://stackoverflow.com/questions/4402036/jquery-ajax-posting-array-to-asp-net-mvc-controller – BradLaney 2013-05-02 20:25:59