Live Chat Icon For mobile
Live Chat Icon

How to refresh a page after the database is updated?

Platform: Blazor| Category : General, Tips and Tricks

After the database is updated, StateHasChanged method can be called to refresh the page/UI. When called, this will rerender the component or the page based on the new changes from the database. 

Razor File

@page "/counter"  
<PageTitle>Counter</PageTitle>  
<h1>Counter</h1>  

<p role="status">Current count: @CurrentCount</p>  

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>  

@code {  
	[Parameter]  
    public int CurrentCount { get; set; } = 0;  

    private async Task IncrementCount ()  
    {  
        CurrentCount++;  
        await InvokeAsync(StateHasChanged);  
    }  
}

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.