angularjs如何将multipul参数传递给api

时间:2017-12-08 14:52:14

标签: angularjs

如何从angularjs传递mutipul参数-to WebAPi My Api作为必需的两个参数

public IHttpActionResult GetData(int pagesize,int Totalpages){---}

angularctrls.js

function GetData() {
        var PageDetails={
            'currentpage': $scope.currentPage,
            'pagesize':$scope.pagesize
        }    
        HomeFactory.GetDat(PageDetails).then(function () {
        })
    }

Factory.js

 EmployeeServiceFactory.GetDat = function (PageDetails) {
        return $http({
            url:WebAPi+'Home/GetData/',
            method: 'GET',
            data: PageDetails,
            headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
        })
}

将错误视为

Failed to load http://localhost:3084/Home/GetData/%7B%22currentpage%22:1,%22pagesize%22:5%7D: No 'Access-Control-Allow-Origin' header is present on the requested resource

2 个答案:

答案 0 :(得分:1)

我认为您可以将数据作为对象。

EmployeeServiceFactory.GetDat = function (PageDetails) { 
  return $http({ 
    url:WebAPi+'Home/GetData/'+PageDetails, 
    method: 'GET', 
    data: {page_details: 
      PageDetails, foo: 'bar'}, headers: { 'Content-Type': 'application/x-www-form-urlencoded' 
    } 
  }) 
}

答案 1 :(得分:1)

尝试params代替data,如下所示:

  EmployeeServiceFactory.GetDat = function (PageDetails) {
            return $http({
                url:WebAPi+'Home/GetData/',
                method: 'GET',
                params: PageDetails,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' }
            })
    }