In my blazor app for administrating cases, I have a property ClaimedBy
on an instance of a class CaseDetails.cs
which holds the username of the administrator who has claimed the case.
It is displayed like this on the index page:
<p>Claimed by: @caseDetails.ClaimedBy</p>
Now, from a child component, I'm trying to update the value of ClaimedBy
like this:
caseDetails.ClaimedBy = newUser;
But the name on the index page (the parent component), is not updated automatically. It updates correctly if I make a button on the index page with a method that calls StateHasChanged()
like this:
<button @onclick="UpdatePage">update page</button>
@code {
private void UpdatePage()
{
StateHasChanged();
}
}
I have tried to call StateHasChanged()
from my child component, in the same method which sets the new value of the ClaimedBy
property, but that doesn't work. StateHasChanged()
has to be called from the parent component. How do I get it to update automatically once the new value has been set?