I have a Blazor server-side page that needs to load data when the user goes to the page. However, after OnAfterRenderAsync executes it does not update the UI. The data is loaded correctly and if I create a "refresh" button to flag the page it works.
I have something like:
@page "/mypage
<button class="btn btn-primary" @onclick="Temp">Refresh</button>
@if (_loading)
{
<p>
<em>Loading...</em>
</p>
}
else
{
<p>
<em>Here is your data</em>
</p>
}
@code {
private bool _loading { get; set; }
protected override async Task OnInitializedAsync()
{
_loading = true;
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender) return;
//Amazong loading code
_loading = false;
}
private void Temp()
{
_loading = false;
}
}
Stepping through the OnAfterRenderAsync does show that _loading is correctly set to false. Stepping through Temp() does show that _loading is set to false.
I am guessing that OnAfterRenderAsync is not updating the DOM, the fact clicking the button forces an update to the DOM.