title: Calling async methods in Blazor view
body: <p>I have a server-side blazor client and I'm trying to modify the MainLayout razor page by having a Login check. I'm currently using Blazored for localstorage saving, and I'm currently using to see if a token is saved to see if user is logged in, however I'm not sure how I translate this in the if statement in razor page because it wants async method.</p>
  
  <p>My login check is pretty simple as shown below.</p>
  
  <pre><code>public async Task&lt;bool&gt; IsLoggedIn()
  {
      return await m_localStorage.ContainKeyAsync("token").ConfigureAwait(false);
  }
  </code></pre>
  
  <p>In my Razor page I'm doing this statement check - which obvious doesn't work as there's no async modifier</p>
  
  <pre><code>@if (!await AppState.IsLoggedIn()) //Requires async modifier
  {
      &lt;a href="Login" target="_blank"&gt;Login&lt;/a&gt;
  }
  </code></pre>
  
  <p>I've also tried doing it using the .Result property, but this results in an exception thrown: (System.AggregateException: 'Information: Executed an implicit handler method, returned result Microsoft.AspNetC)' with an inner-exception -> NullReferenceException: Object reference not set to an instance of an object. </p>
  
  <p>But from what I can see AppState is injected correctly and the local storage seems to be injected correctly in AppState.</p>
  
  <pre><code>@if (!AppState.IsLoggedIn().Result)
  {
      &lt;a href="Login" target="_blank"&gt;Login&lt;/a&gt;
  }
  </code></pre>
  
  <p>So my question is what is the correct way to approach this, is there a way to execute async methods in razor pages?</p>