Search code examples
c#jqueryajaxasp.net-web-apirestangular

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:

[HttpDelete]
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"};
Students.one(1234).remove(so);

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.


Solution

  • 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.