Md Ghousemohi
Md Ghousemohi

Reputation: 197

angularjs how can pass multipul parameter to api

How can I pass mutipul parameters from angularjs -to WebAPi My Api as its Required two parameters

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' }
        })
}

Getting Error as

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

Upvotes: 0

Views: 49

Answers (2)

Bassem Mamar
Bassem Mamar

Reputation: 328

try params instead of data like below:

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

Upvotes: 1

Benjamin Audet
Benjamin Audet

Reputation: 493

I think you can put data as an object.

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' 
    } 
  }) 
}

Upvotes: 1

Related Questions