C# blazor await function to get property

lukas9669

Member
Joined
Feb 7, 2022
Messages
9
Programming Experience
1-3
I am programming a C# blazor game, and there is a method that sets a property in a class. If the button, which calls the method was clicked, on the next page the property will be printed.
Here is a simplified example:

C#:
class A{
    public string test {get; set;}
}

class B{
    public void StartGame()
    {
        //start game
        //here is a string word
        A a = new A();
        a.test = word;
    }
}

//html
<div>
@a.test
</div>



So the problem is. if the method will be called the initialising process of the game isnt finished, and the property is still null.
How can I await the method so that the property will be printed?
 
Will that even work? a is local to StartGame(). It won't get exposed out to the page.

I'm not familiar with the Blazor page lifecycle. But what I would do in your shoes is to research how the Blazor page lifecycle and update process works, and then try to insert the property initialization before the page render or page update.
 

Latest posts

Back
Top Bottom