如何在jQueryAjax中传递数组,以及如何在服务器端协调数组?

如何在jQueryAjax中传递数组,以及如何在服务器端协调数组?,jquery,asp.net,json,asp.net-mvc-3,Jquery,Asp.net,Json,Asp.net Mvc 3,我有一个问题,我必须将一个ID列表传递给服务器端以删除一些用户,但我的要求是使用jQueryAjax。但是我无法在我的服务器端获得参数。有人能帮我解决这个问题吗 我迄今为止所做的工作如下所示 var idList = new Array(); $(document).ready(function () { $('input:checkbox').click(function () { //set our checkedcount variable to 0

我有一个问题,我必须将一个ID列表传递给服务器端以删除一些用户,但我的要求是使用jQueryAjax。但是我无法在我的服务器端获得参数。有人能帮我解决这个问题吗

我迄今为止所做的工作如下所示

  var idList = new Array();
$(document).ready(function () {
    $('input:checkbox').click(function () {
        //set our checkedcount variable to 0
        var checkedCount = 0;
        //loop through and count the number of "checked" boxes
        $('.acceptUsers:checked').each(function () {
            //if a checked box was found, increase checkedCount by 1
            idList.push($(this).val());
            checkedCount++;
        });
    });
});
      $('#btnDelete').click(function () {
          url = 'Teacher/UpdateUserStatus/';
          var ids = idList.toString();
          $.ajax({
              type: "POST",
              url: url,
              data: { 'userIds': ids },
              contentType: "application/json; charset=utf-8",
              dataType: "html",
              success: function (data) {
                  alert('yeah');
                }
              }
          });
      });
我在服务器端所做的是

    [HttpPost]
    public JsonResult UpdateUserStatus(object userIds)
    {
        List<int> usersToDelete = new JavaScriptSerializer().ConvertToType<List<int>>(userIds);
        this.userService.DeleteUsers(usersToDelete);
        return Json(true, JsonRequestBehavior.AllowGet);
    }
[HttpPost]
公共JsonResult UpdateUserStatus(对象用户ID)
{
List usersToDelete=new JavaScriptSerializer().ConvertToType(userid);
this.userService.DeleteUsers(usersToDelete);
返回Json(true,JsonRequestBehavior.AllowGet);
}

有人知道为什么我的服务器端方法没有调用吗?

我注意到的第一件事是,代码中额外有一个花括号。请尝试以下方法:

 $('#btnDelete').click(function () {
      url = 'Teacher/UpdateUserStatus/';
      var ids = idList.toString();
      $.ajax({
          type: "POST",
          url: url,
          data: { 'userIds': ids },
          contentType: "application/json; charset=utf-8",
          dataType: "html",
          success: function (data) {
              alert('yeah');
          }
      });
  });
如果这不起作用,请启动调试会话,并在action方法上设置一个断点,然后查看是否正在运行服务器

另请参阅以下文章,了解ASP.NET MVC 3上的JQuery Ajax调用示例:


我已经解决了问题并找到了问题。实际上,我传递paratemets的方式是错误的,因为我没有在服务器端得到调用,我已经使用数据解决了这个调用:“{'userIds':'“+ids+”}”