【发布时间】:2014-09-19 12:54:58
【问题描述】:
var checkedValues = $('.required:checked').map(function () {
return this.value;
}).get();
var arr = new Array(10);
alert(checkedValues);
alert("number of values in it " +checkedValues.length);
if (checkedValues.length > 1) {
alert("I am inside if ");
arr = checkedValues.split(',');
alert("I am done with the split ");
}
else {
arr = checkedValues;
alert("No split needed ");
}
$.getJSON('@Url.Action("testcata", "home")' + + '?Type=' + "@(Session["typ"])" + "&city=" + "@(Session["cit"])" + "&chkd=" + checkedValues,
function (data) {
//code
})
In controller :
public ActionResult testcata(string Type, int? city, int[] chkd)
{
//code
}
我正在尝试获取选中的复选框的值并将它们存储在数组中,然后通过 json 函数发送到控制器。 alert("I'm done with the split") 未显示。请帮帮我。
【问题讨论】:
-
使用控制台日志代替警报
-
你能显示html吗?
-
checkedValues已经是一个数组。你想分裂什么? -
你知道jquery的.map函数返回一个数组吗? api.jquery.com/jquery.map
-
@onetrickpony - 那么为什么控制器中的方法将 null 作为多个选定检查值的参数?我在函数中有一个 int[] chkd 参数。它显示为空
标签: javascript jquery json forms