title: How do I write Blazor HTML code inside the @code block?
body: <p>How can I write Blazor HTML code within a function inside of the <code>@code</code> block?</p>
  
  <p>Consider the following code:</p>
  
  <pre><code>@page "/Test"
  
  @if (option == 1)
  {
      drawSomething("Something");
  }
  else
  {
      drawSomething("Something else");
  }
  
  @code {
      int option;
  
      void drawSomething(string message)
      {
          &lt;p&gt;message&lt;/p&gt;
      }
  }
  </code></pre>
  
  <p>It does not produce any errors until I try to build, then it gives me the following error:</p>
  
  <blockquote>
    <p>Error CS0103  The name '__builder' does not exist in the current
    context</p>
  </blockquote>
  
  <p>On the lines in (<code>Test.razor.g.cs</code>):</p>
  
  <pre><code>__builder.AddContent(0, "        ");
  __builder.AddMarkupContent(1, "&lt;p&gt;message&lt;/p&gt;\r\n");
  </code></pre>
  
  <p>It seems very limited if this means Blazor HTML code can only be written in the first part of the file and not inside functions or classes.</p>
  
  <p>I'm using the latest version as of writing version (<code>3.0.100-preview9-014004</code>) of blazor. </p>
  
  <p>Note: The output in the given example is highly simplified, and I would like to know if and how I am able to write code from within a function and not solve the output above in a better way.</p>