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?
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 edited Sep 5, 2014 at 9:36 ahmadalibaloch asked Sep 5, 2014 at 7:36 ahmadalibalochahmadalibaloch 6,0213 gold badges53 silver badges61 bronze badges1 Answer
Reset to default 4Tested 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)
});