Tham số string[] orderTypeNames
sắp xuất hiện.Mô hình MVC ràng buộc một mảng chuỗi từ bài đăng jQuery
hành động 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) {
//...
});
});
cáy
orderIds%5B%5D=97&orderIds%5B%5D=98&orderIds%5B%5D=93&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder
Đây có phải là dấu ngoặc vuông gây ra sự cố không? Làm thế nào tôi có thể liên kết với các mảng này?
Chỉnh sửa: Tôi đang tạo chuỗi truy vấn theo cách thủ công trong thời gian trung bình.
query = "";
for each...
query += "orderIds=" + $order.attr("orderId") + "&";
query += "orderTypeNames=" + $order.attr("orderType") + "&";
Sử dụng giải pháp được đăng tại đây. http://stackoverflow.com/questions/4402036/jquery-ajax-posting-array-to-asp-net-mvc-controller – BradLaney