正在获取控制器的null值's使用jquery从javascript传递的操作

Getting null value to controller's action passing from javascript using jquery

本文关键字:jquery 使用 javascript 操作 控制器 获取 null      更新时间:2023-09-26

我在项目中尝试的是将复选框的选定值作为逗号分隔的字符串传递到控制器的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;
 }

您可以看看这篇文章:JavaScript字符串数组到JsonResult作为列表的AJAX帖子<字符串>总是返回Null?或者这个:用jQuerygetJson发送列表/数组作为参数。似乎您必须在ajax调用中指示traditional: true

在脚本中使用这个:

var did ='',
$("#tbl").find("input:checkbox").each(function (i) {
    if (this.checked == true) {
        did += $(this).val() + ",";
    }
});
alert(did); 
if (did == "") {
    alert("Please Select"); 
    return; 
}