如何将数组传递给webapi函数?

时间:2016-06-28 11:06:15

标签: angularjs

我想将数组传递给webapi。

以下是我在albumNameArray中获取复选框选定项目的功能。

$scope.Delete = function () {
        debugger
        $scope.albumNameArray = [];
        angular.forEach($scope.InboxList, function (CU) {
            if (CU.selected) $scope.albumNameArray.push(CU.InboxMailID);
        })
    }

现在我想将albumNameArray发送到webapi函数中。我修改了删除功能,但它无法正常工作,我的代码出了什么问题?

$scope.Delete = function () {
        debugger
        $scope.albumNameArray = [];
        angular.forEach($scope.InboxList, function (CU) {
            if (CU.selected) $scope.albumNameArray.push(CU.InboxMailID);
        }).$http({
        url: "MailRoute/DeleteSelecetedEmail",
        dataType: 'json',
        method: 'POST',
        data: albumNameArray,
        headers: {
            "Content-Type": "application/json"
        }

    }).success(function (response) {
        debugger
        if (response != null) {

        }

    })
      .error(function (error) {
          alert(error);
      });
}

2 个答案:

答案 0 :(得分:0)

这是我声明的模型类

public class GetAllInbox
    {
        public string data{ get; set; }
   } 

webpai功能如下所示

public HttpResponseMessage Delete(HttpRequestMessage request, [FromBody]GetAllInbox obj)
    {

        if (something!= 0)
        {

        }
        else
        {

        }

        return response;
    }

这是我的webapi代码。

答案 1 :(得分:0)

试试这个:

public HttpResponseMessage Delete(string data)
{
    if (something!= 0)
    {

    }
    else
    {

    }
    return response;
}

如果这不起作用请尝试使用列表

相关问题