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);
}
Reference link:
Share with