Loading, please wait...

How do you send an HTTP PUT request using HttpClient in Blazor?

This code will help you to understand how to send an HTTP PUT request using HttpClient in Blazor.

The HTTP PUT method is used to completely replace a resource on the API server. We can use the HttpClient to send a PUT request to an API server using the SendJsonAsync () method.

CSHTML

@page "/employee/edit"
@inject HttpClient Http

.. .. .. .. .. .. 
.. .. .. .. .. ..

@code {
    Employee emp = new Employee();
    protected async Task UpdateEmployee()
    {
        await Http.SendJsonAsync(HttpMethod.Put, "api/Employee/Edit", emp);
        UriHelper.NavigateTo("/employee");

    }
}

WEB API

[HttpPut]
[Route("api/Employee/Edit")]
public void Edit([FromBody]Employee employee)
{
    if (ModelState.IsValid)
        this.employee.UpdateEmployee(employee);
}

I would suggest you check the below link for better understanding:
https://medium.freecodecamp.org/how-to-create-an-application-using-blazor-and-entity-framework-core-1c1679d87c7e