0

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
12
  • when i convert data in Json obj its throughing an error as A potentially dangerous Request.Path value was detected from the client (:). Commented Dec 8, 2017 at 14:58
  • Maybe your back doesn't accept multiple keys as data Commented Dec 8, 2017 at 14:59
  • why not its suppport Commented Dec 8, 2017 at 15:00
  • correct this from url:WebAPi+'Home/GetData/'+PageDetails to url:WebAPi+'Home/GetData/' and methode ? should be method @MdGhousemohi and is your response status 404 ? Commented Dec 8, 2017 at 15:10
  • @supercool when i change url as your suggest even im getting same Error And My response is404 Commented Dec 8, 2017 at 15:13

2 Answers 2

1

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' }
            })
    }
Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.