Home > Software design >  .NET 6 API method is not working after migration to .NET 6
.NET 6 API method is not working after migration to .NET 6

Time:02-02

I have the following API Method that was working fine before .NET 6 migration.

[Route("employee/update")]
[HttpPut]
[JwtAuthentication]
public async Task<IActionResult> Put([FromQuery] int id, Employee employee){
....
}

This is how I was calling it from Blazor app:

httpResponse = await Http.PutAsJsonAsync($"employee/update?id={Employee.Id}", employeeModel);

The code is never into the API method and I get on Blazor a httpResponse.IsSuccessStatusCode = false 400 Http Error Bad Request.

Any clue on what changed in the framework that I have to change?

CodePudding user response:

since you are using json, you have to add frombody attribute

public async Task<IActionResult> Put([FromQuery] int id,[FromBody] Employee employee)
  •  Tags:  
  • Related