Hi
Here is the answer to your question: https://learn.microsoft.com/en-us/answers/questions/1378821/blazor-accessing-global-variable-issue
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
How to declare global variables in Blazor , for example I have inputquestions in Index I want to use this in another page called Quiz.
@page "/"
<h1> Quiz </h1>
Select Input Questions and
Click on Quiz .
<div class="row">
<p>Questions:</p>
<input type="range" min="5" max="20" step="5" @bind="@inputquestions"
@bind:event="oninput" />
</div>
<p>@inputquestions</p>
@code {
public int inputquestions=5;
}
Hi
Here is the answer to your question: https://learn.microsoft.com/en-us/answers/questions/1378821/blazor-accessing-global-variable-issue
in addition to cascading state you have:
note: while using a static would work with a Blazor WASM, it will not work with server pre-render or server Blazor as the static value would be shared between all Blazor instances.
you did not define a @rendermode, so the default is static (no javascript events).