I am working on a Vue + ASP.NET Core 3.1 with OData endpoint app and I'm working out how to delete items. So far I can delete a single item in the backend. I am still quite new to all this just looking for a bit of guidance on the issue.
Now I need to set it up to delete multiple selected items that is sent via an axios call to the backend. I am having trouble setting up the delete method to delete multiple files as well as testing it in postman
This is the code I have so far
[HttpDelete("{key}")]
public async Task<ActionResult<Asset>> DeleteAsset(List<int> key)
{
var asset = await _context.Assets.FindAsync(key);
var assets = _context.Assets.ToList().Where(a => a.Id == 0);
if (asset == null)
{
return NotFound();
}
_context.Assets.Remove(asset);
await _context.SaveChangesAsync();
return asset;
}
How can I set this up to accept multiple Id's sent from the front end in an axios.delete
call and have it delete those items from the database?
I know I can also use .RemoveRange()
but again cannot figure out how to get it set up with out it giving me a conversion error on the return
I also would like to know how I can test this method using postman?
Any guidance would be appreciated .
Update:
This is my endpoint configuration in startup.cs
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
endpoints.MapODataRoute("odata", "odata", GetEdmModel(app.ApplicationServices), batchHandler: new DefaultODataBatchHandler());
endpoints.Select().Expand().OrderBy().Filter().Count().MaxTop(null);
});
When I have the action setup for single item delete it works, When I do it for the multiple delete It does not even fire. I just get the dead error in postman