title: Dynamic _Hosts.cshtml file in Blazor with C# code
body: <p>Just used the great free Blazor code of DevExpress to implement custom <code>&lt;HEAD&gt;</code> data on runtime:</p>
  
  <p>_Hosts.cshtml (see the code snippet in  element):</p>
  
  <pre><code>    &lt;!DOCTYPE html&gt;
      &lt;html lang="en"&gt;
      &lt;head&gt;
          @(await Html.RenderComponentAsync&lt;DocumentMetadataComponent&gt;(RenderMode.ServerPrerendered))
      &lt;/head&gt;
      &lt;body&gt;
          &lt;app&gt;
              @(await Html.RenderComponentAsync&lt;App&gt;(RenderMode.ServerPrerendered))
          &lt;/app&gt;
      &lt;script src="_framework/blazor.server.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  </code></pre>
  
  <p>Works great so far (can make title, description, etc. dynamic).</p>
  
  <p>Problem now is that I have to set some variables on that top Level to overgive and interpret once.
  I want to know the used url and give some data dynamically.</p>
  
  <p>But with my knowledge right now I just can do it twice in each component (DocumentMetadataComponent + App).</p>
  
  <p>I'm getting data in MainLayout.razor:</p>
  
  <pre><code>&lt;CascadingValue Value="StoreData" Name="StoreData"&gt;
      @Body
  &lt;/CascadingValue&gt;
  
  @code{
      public StoreCompleteDTO StoreData { get; set; }
  
      protected override async Task OnInitializedAsync()
      {
          using var tl = new TimeLogger($"MainLayout.razor OnInitializedAsync()");
  
          StoreData = await AppState.GetStoreData(My.StoreId);
      }
  }
  </code></pre>
  
  <p>This StoreData variable must be available in dynamic meta data, because I have to choose different CSS files for other stores...</p>
  
  <p>Hope the explanation is clear.</p>
  
  <p>Goal is call this just ONCE:
      StoreData = await AppState.GetStoreData(My.StoreId);</p>
  
  <p>because it is web service call and costs time... </p>
  
  <p>Thx!</p>