Q:

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

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

An HTTP POST request can be sent to add new data in the API server using the SendJsonAsync () method provided by the HttpClient class.

Razor

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

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

@code {
    Employee emp = new Employee();
    protected async Task CreateEmployee()
    {
        await Http.SendJsonAsync(HttpMethod.Post, "/api/Employee/Create", emp);
    }
}

web API

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

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now