I have a service.ts file that calls HTTP Client method to delete multiple records from db. But when I’m passing multiple Id’s in an array it’s not getting deleted and an error shows up in the network.
Controller.cs
[HttpDelete]
public void DeleteMulipleDevice([FromQuery]int[] deviceIds)
{
try
{
_frontLineContext.Devices.RemoveRange(_frontLineContext.Devices.Where(d => deviceIds.Contains(d.Id)));
_frontLineContext.SaveChanges();
}
catch (Exception)
{
}
}
service.ts
public deleteMulipleDevices(deviceIds: any): Observable<any> {
let params = new HttpParams().set("deviceIds", deviceIds);
return this.http.delete<any[]>(this.baseUrl + 'device', { params });
}
deviceIds = [1,2,3,4] looks like this.
What wrong should I add to the service.ts or Controller file to delete multiple records from the table?
2
Answers
change the
service.ts
so that thedeviceIds
parameter look like thisdeviceIds=19&deviceIds=20
instead ofdeviceIds=19,20
then in your api method change[FromQuery]
to[FromQuery(Name="deviceIds")]
I just had to do replace my service.ts with this code