How to declare global variables in Blazor

Maui Learner 520 Reputation points

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">
    <input type="range" min="5" max="20" step="5" @bind="@inputquestions"
     @bind:event="oninput" />
@code {
    public  int inputquestions=5;
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,448 questions
0 comments No comments
{count} votes

2 additional answers

Sort by: Most helpful
  1. Bruce ( 59,036 Reputation points

    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.

  2. Bruce ( 59,036 Reputation points

    you did not define a @rendermode, so the default is static (no javascript events).

    0 comments No comments