Live Chat Icon For mobile
Live Chat Icon

How do you render a Blazor page after the parameter is updated?

Platform: Blazor| Category: General

Blazor updates the UI every time a parameter updates. Invoking an external StateHasChanged() might be required when updating parameters as a result of any async operation.

[Counter.razor] 

@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++; 
        // Call StateHasChanged to trigger a re-render of the page 
        await InvokeAsync(StateHasChanged); 
    } 
} 

StateHasChanged tells Blazor to update the UI when it is called. 
https://stackoverflow.com/questions/55809117/blazor-page-not-rerendering-after-parameter-updated

Share with

Related FAQs

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

Please submit your question and answer.