gpt4 book ai didi

javascript - Json函数不传递数组

转载 作者:行者123 更新时间:2023-12-02 16:58:46 26 4
gpt4 key购买 nike

var checkedValues = $('.required:checked').map(function () {
return this.value;
}).get();

$.getJSON('@Url.Action("testcata", "home")' +"?Type=" + "@(Session["typ"])" + "&city=" + "@(Session["cit"])" + "&chkd=" + checkedValues,
function (data) {
//code
})

在 Controller 中:

public ActionResult testcata(string Type, int? city, int[] chkd)
{
//code
}

我正在尝试获取通过 json 函数检查的复选框的值。 为什么 Controller 中的方法将 null 作为多个选定检查值的参数?我在函数中有一个 int[] chkd 参数。显示为空。

最佳答案

您正在尝试将数组作为字符串。试试这个:

var checkedValues = encodeURIComponent($('.required:checked').map(function(){
return this.value;
}).get().join());

关于javascript - Json函数不传递数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25945786/

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