我在我的项目中尝试的就像将复选框的选定值作为逗号分隔的字符串传递给我的控制器的json ..但是我没有得到json操作的值..它在那里显示为null。
我该怎么做?请帮帮我
function getIds(checkList)
{
var idList = new Array();
var loopCounter = 0;
jQuery("input[name=" + checkList + "]:checked").each
(
function()
{
idList[loopCounter] = jQuery(this).val();
loopCounter += 1;
}
);
alert(idList);
jQuery.getJSON("/Photos/CheckForIdsJson", { idList: idList });
}
[AcceptVerbs(HttpVerbs.Get)]
public JsonResult CheckForIdsJson(Int32[] idList)
{
JsonResult result = new JsonResult();
result.Data = idList;
return result;
}
答案 0 :(得分:0)
您可以查看以下帖子:AJAX Post of JavaScript String Array to JsonResult as List<string> Always Returns Null?或此帖:Send list/array as parameter with jQuery getJson。您似乎必须在ajax调用中指出traditional: true
。
答案 1 :(得分:0)
在您的脚本中使用它:
var did ='',
$("#tbl").find("input:checkbox").each(function (i) {
if (this.checked == true) {
did += $(this).val() + ",";
}
});
alert(did);
if (did == "") {
alert("Please Select");
return;
}