ASP.NET Blazor
ASP.NET MapDelete Api 에러 해결
힐프
2023. 10. 11. 11:08
System.InvalidOperationException: 'Body was inferred but the method does not allow inferred body parameters.
Below is the list of parameters that we found:
app.MapDelete("/test", async (SomeClass json) => { });
body로 부터 전달 받은 값을 토대로 API를 구성하고자 할 때 위와 같은 문제가 발생합니다.
// Route
app.MapDelete("/test/{id}", async (int id) => { });
// Body
app.MapDelete("/test", async (SomeClass json) => { });
프레임워크가 둘 중 어느 방식으로 매개변수를 추론해야하는지 알기 어렵기 때문에 발생합니다.
따라서, 그냥 알려주면 됩니다.
// Route
app.MapDelete("/test/{id}", async ([FromRoute] int id) => { });
// Body
app.MapDelete("/test", async ([FromBody] SomeClass json) => { });
// Both
app.MapDelete("/test/{id}", async ([FromRoute] int id, [FromBody] SomeClass json) => { });
(이상하게도 GET, POST, PUT 은 별 다른 이상이 없었는데 DELETE만 에러가 발생합니다)