I defined a static class in order to share data among different razor pages.Here is the class:
namespace BlazorTest{ public static class General { public static int number; }}This is my parent razor:
@page "/"<button @onclick="()=>Increase()">Increase</button><br />Here is parent page.<br />@General.number<br /><Child />@code{ protected override void OnInitialized() { base.OnInitialized(); General.number = 0; } void Increase() { General.number++; StateHasChanged(); }}This is my child razor:
<button @onclick="()=>Increase()">Increase</button><br />Here is child page.<br />@General.number@code { void Increase() { General.number++; StateHasChanged(); }}When I click the button four times in the child page, the output is:
Here is parent page.0Here is child page.4Then I click the parent button once, it becomes:
Here is parent page.5Here is child page.4Can I synchronize the public static class?