I have built a web assembly blazor project.
In one of its blazor components, there is a Form to submit new data.
This form, POST the data to server via a web api to save in database.
<EditForm Model="@person"> <div class="col-12 row"> <label class="col-2 font-weight-bold">Id : </label> <InputNumber class="form-control col-3" @bind-Value="person.Id" placeholder="id" /> </div> <br /> <div class="col-12 row"> <label class="col-2 font-weight-bold">Name : </label> <InputText class="form-control col-3" @bind-Value="person.Name" placeholder="name" /> </div> <input type="submit" class="form-control btn btn-primary text-center" @onclick="@AddPerson" value="Add" /> </EditForm> The C# code behind @AddPerson is this :
@code { public List<Person> people; public Person person = new Person(); private async void AddPerson() { HttpResponseMessage httpResponse = await Http.PostAsJsonAsync<Person>("https://apisite.ir/api/people", person); people = await Http.GetFromJsonAsync<List<Person>>("https://apisite.ir/api/people"); } } The people list is being shown in such a table in a foreach like this :
<table class="table"> <thead> <tr> <th>ID</th> <th>Name</th> </tr> </thead> <tbody> @foreach (Person p in people) { <tr> <td>@p.Id</td> <td>@p.Name</td> </tr> } </tbody> </table> The problem is that, when I click Add button , both api call happen, BUT nothing in the UI changes.
The table which suppose to show list of people would not update.
What should I do ?