gpt4 book ai didi

c# - MVC 模型绑定(bind)来自 jQuery post 的字符串数组

转载 作者:数据小太阳 更新时间:2023-10-29 05:26:59 25 4
gpt4 key购买 nike

参数 string[] orderTypeNames 即将变为 null。

mvc Action

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) {
//...
});
});

fiddler

enter image description here

orderIds%5B%5D=97&orderIds%5B%5D=98&orderIds%5B%5D=93&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder&orderTypeNames%5B%5D=DeliveryOrder

是方括号引起的问题吗?如何绑定(bind)到这些数组?

编辑:我同时手动构建查询字符串。

query = "";
for each...
query += "orderIds=" + $order.attr("orderId") + "&";
query += "orderTypeNames=" + $order.attr("orderType") + "&";

最佳答案

您需要对数据调用某种JSON.stringify

 $.post('EditMultipleOrderStates', JSON.stringify(data), function (response) {
//...
});

关于c# - MVC 模型绑定(bind)来自 jQuery post 的字符串数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11582914/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com