Gagan Bajaj Gagan Bajaj - 5 months ago 26x
jQuery Question

Can we pass array as parameter to Delete() action in WebAPI from jQuery Ajax call?

I am using WebAPI and implemented a controller method Delete with HTTP verb as [HTTPDELETE]. Please find the syntax below:

public Resonse Delete([FromBody]Guid[] input)
\\method processing

I am using RestAngular to call this method.

let so = {"asde-wert-wedc-ewsdc", "asde-wert-wedc-ewsdc"};;

When I am trying to run it. I am getting 500 internal server error.

I need to pass an array of Guid to my Delete method in controller using restangular.


After some hit and trials I got the answer. I need to apply custom operation in restangular:

Get all the elements in an array

this.objectlist = [];

Pass the array as a parameter.

this.restangular.all(this.route).customOperation("remove",this.route, null, {"Content-Type":"application/json;charset=utf-8"}, {objectIds:objectlist});

Please do mention content type otherwise it will not work.