Undocumented TypeError: Window.fetch: HEAD or GET Request cannot have
a body.The C# code in the controller. It won't even hit my debug point
at var results.
Issue Reproduced:
I have tried to reproduce your issue and successfully simulated as expected. As you can see below:

Why Not Working:
Well, the error you are getting is pretty obvious in reagrds of swagger and Http verb GET
as Body payloads are not supported by swagger in a GET operation, and is typically not supported by any server frameworks for instance asp.net core web api, even though the http specification is vague about supporting them.
Swagger and asp.net core web api only allow request body on POST
, PUT
, and PATCH
request.
Solution:
Using model binding we can force asp.net controller to accept request body in HttpGET
request. Specifically, we can use [FromQuery]
to pass your BankTransactionDto
and it will accept the body thus, hit your debugger point.
You could update your code as following:
[Route("api/[controller]")]
[ApiController]
public class BankTransactionController : ControllerBase
{
[HttpGet(Name = "GetAccountBalance")]
public async Task<ActionResult<BankTransactionDto>> GetAccountBalance([FromQuery] BankTransactionDto bankDto)
{
var results = await _bankTransactionService.GetTotalBalance(bankDto);
return Ok(bankDto);
}
}
public class BankTransactionDto
{
public string Id { get; set; }
public string Name { get; set; }
public decimal Amount { get; set; }
}
Note: You can use [HttpGet("GetAccountBalance")]
If you want your swagger URL to display as like /api/BankTransaction/GetAccountBalance
Output:

Note: If you need more information, you could refer to following official documnet.
- Asp.net core web API Http verb Request Body format.
- Swagger Request Body documnt