I'm new to web development in general, and so I'm suspecting that i have misunderstood the core premise of razor pages.
I am trying to add a loading indicator to my page while I'm pulling data. While this could be achieved with a js promise, i was under the assumption that i could do this entirely in c# with the cshtml files.
In my controller i have a Page model looking like so:
public Boolean IsLoading { get; set; } = true;
public async Task<IActionResult> OnGetAsync()
{
await Task.Run(() =>
{
Thread.Sleep(1000 * 10);
IsLoading = false;
});
return Page();
}
Just something to simulate an expensive database query, and a bool to indicate when loading is done.
In my pagefile i have something looking like this:
@if (@Model.IsLoading)
{
<div>
<img src="~/Images/loading.gif" />
</div>
}
else
{
<div>
<<Some Code Showing My Data>>
</div>
}
I have tried multiple ways to try and update the model or redraw the page when the data pull is finished, but i have been unable to find any ways that work.
The desired behavior is to have the page show the loading symbol up until the 'database query' finished and then display the data instead.
The current behavior that i am seeing is that the page will not percent until the 'database query' has finished. So I never see the loading gif.