Using ASP.NET Core 3.1 and Microsoft.AspNetCore.OData 7.5.6,
When a HTTP "DELETE" request is sent to an action method, I am unable to get the
query parameter, the resulting parameter value remains set to 0.
Here is my HTTP Request:
https://localhost:8083/api/EventTypes(Id=66L)
And my Action Method:
[Route("api/EventTypes({Id})")]
[HttpDelete]
// [AcceptVerbs("DELETE")]
public async Task<IActionResult> Delete(Int64 Id)
{
DynamicParameters param = new DynamicParameters();
param.Add("Id", Id);
await Dapper.DapperORM.ExecuteWithoutReturn("event_type_delete", param);
return Ok();
}
When I inspect the value of Id the value is 0. I have tried changing the type to string, and then the value is set to "Id=66L".
I expect this to work but it does not in my case:
Delete([FromODataUri]Int64 Id)
What is the best/correct way to get the integer value?
CodePudding user response:
Changing the Route Parameter to use this format Id={Id} and using FromODataUri I managed to get the desired parameter value.
e.g.
[Route("api/EventTypes(Id={Id})")]
[AcceptVerbs("DELETE")]
public async Task<IActionResult> Delete([FromODataUri]Int64 Id)
