问题是{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控制器中获得categoryId
和currentPageNum
的值,但brandSelection
值始终为null。
答案 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);
}