This code will help you to understand how to send an HTTP POST request using HttpClient in Blazor
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); }
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
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
web API
need an explanation for this answer? contact us directly to get an explanation for this answer