无法将angularjs服务中的数组传递给web api

时间:2014-10-09 17:29:47

标签: angularjs mongodb asp.net-web-api mongodb-.net-driver

问题是{apid控制器未传递brandSelection值>>>

这是来自Angular Service的$http.get()电话:

   var _getItemByCategoryId = function (categoryId, currentPageNum, brandSelection) {

        var deferred = $q.defer();

        $http.get("Item/GetItemByCategoryId/categoryId/" + categoryId + "/currentPageNum/" + currentPageNum, { params: brandSelection }).success(deferred.resolve).error(deferred.reject);

        return deferred.promise;

};

这是WEBAPI代码:

    [HttpGet]
    [Route("Item/GetItemByCategoryId/categoryId/{categoryId}/currentPageNum/{currentPageNum}")]
    public IHttpActionResult GetItemByCategoryId(string categoryId, int currentPageNum, string[] brandSelection)
    {
        var item = _itemService.GetItemByCategoryId(categoryId, currentPageNum);
        return Ok(item);
    }

问题是我在此Web api控制器中获得categoryIdcurrentPageNum的值,但brandSelection值始终为null。

1 个答案:

答案 0 :(得分:1)

使用[Formuri]

[HttpGet]
[Route("Item/GetItemByCategoryId/categoryId/{categoryId}/currentPageNum/{currentPageNum}")]
public IHttpActionResult GetItemByCategoryId(string categoryId, int currentPageNum, [FromUri] string[] brandSelection)
{
    var item = _itemService.GetItemByCategoryId(categoryId, currentPageNum);
    return Ok(item);
}