title: Nested if statement is confusing Razor
body: <p>I'm trying to set up a dropdown menu that pulls from a Datatable. This works just fine for the first level of the menu.</p>
  
  <p><strong>Working code:</strong></p>
  
  <pre><code>&lt;ul class="dropdown-menu"&gt;
  @foreach (System.Data.DataRow dr in menu.Rows)
  {
      if (Level1 != dr["Level1"].ToString())
      {
          &lt;li&gt;&lt;a href="#"&gt;@dr["Level1"].ToString()&lt;/a&gt;&lt;/li&gt;
          Level1 = @dr["Level1"].ToString();
      }
  }
  &lt;/ul&gt;
  </code></pre>
  
  <p>The problem occurs when I try to add a nested if statement. If you put this code into Visual Studio you will notice that the closing bracket for the <code>@foreach</code> loop is not recognized by Razor.</p>
  
  <p><strong>Code breaks:</strong></p>
  
  <pre><code>&lt;ul class="dropdown-menu"&gt;
  @foreach (System.Data.DataRow dr in menu.Rows)
  {
      if (Level1 != dr["Level1"].ToString())
      {
          &lt;li&gt;&lt;a href="#"&gt;@dr["Level1"].ToString()&lt;/a&gt;&lt;/li&gt;
          Level1 = @dr["Level1"].ToString();
  
          if (Level2 != dr["Level2"].ToString())
          {
              &lt;li&gt;&lt;a href="#"&gt;@dr["Level2"].ToString()&lt;/a&gt;&lt;/li&gt;
              Level2 = @dr["Level2"].ToString();                                        
          } 
      }
  } &lt;!-- the issue is the bracket on this line --&gt;
  &lt;/ul&gt;
  </code></pre>