Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am sending an array of integers to the web api controller method successfully using angularjs $resource custom method without params defined. When I add other parameters with an array type parameter and define it in $resource custom method then other parameters are received successfully but the array found null. Here is the code with only array that is working fine. AngularJS Service

 var Product_Service = $resource('api/Product/:productId', { productId: '@id' },
   {
       'update': { method: 'PUT' },
       'bulkDelete': {
           method: 'POST',
           url: 'api/Product/BulkDelete',
           isArray:true
       }
    }

Calling it like this (passing directly the array):

bulkDelete: function (productIds) {
                var deferred = $q.defer();
                Product_Service.bulkDelete(productIds, function (response) {
                    deferred.resolve(response);
                }, function (response) {
                    deferred.reject(response);
                });
                return deferred.promise;
            },

Server side:

  [Route("BulkDelete")]
    public HttpResponseMessage BulkDelete(int[] ProductIds)
    {

        return Request.CreateResponse(HttpStatusCode.OK);
    }

Problem: I want to receive this array with another parameter but in that case array is received with value null.

  [Route("BulkDelete")]
    public HttpResponseMessage BulkDelete(int[] ProductIds,string hi)
    {
        //now ProductIds is null with another string hi parameter
        return Request.CreateResponse(HttpStatusCode.OK);
    }

angularjs service:

'bulkDelete': {
           method: 'POST',
           url: 'api/Product/BulkDelete',
           isArray:true,
           params:{
               productIds:'@productIds',
               hi:'@hi'
           }
       }

Now m calling like this,

bulkDelete: function (productIds) {
                var deferred = $q.defer();
                Product_Service.bulkDelete({productIds:productIds,hi:'hi how'}, function (response) {
                    deferred.resolve(response);
                }, function (response) {
                    deferred.reject(response);
                });
                return deferred.promise;
            },

Where is the problem and is that possible? If yes where I need to amend?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Tested and it's working

API Controller

[Route("api/Product/BulkDelete")]
[HttpPost]
 public HttpResponseMessage BulkDelete(string hi, int[] productIds)
 {
            //now ProductIds is null with another string hi parameter

            return Request.CreateResponse(HttpStatusCode.OK);
 }

RESOURCE

 var Product_Service = $resource('api/Product/:productId', { productId: '@id' },
   {
       'update': { method: 'PUT' },
       'bulkDelete': {
           method: 'POST',
           url: 'api/Product/BulkDelete',
           isArray:true,
           params:{

               hi:'@hi'
           }
       }
    }

CALL TO API

var productIds = [1, 2, 3, 4];
Product_Service.bulkDelete({ hi:'hello' },productIds, function (response) {
console.log(response) 
});
share|improve this answer
    
Thanks a lot worked at GO! –  ahmadalibaloch Sep 5 '14 at 11:18

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.