title: Razor & nested loops
body: <p>I am just started to learn Razor and have a question regarding nested loops.</p>
  
  <p>It renders everything correctly using the following code</p>
  
  <pre><code>@foreach (var group in Model.Groups)
  {
      foreach (var item in group.Items)
      {
          &lt;span&gt;@item.Title&lt;/item&gt;
      }
  }
  </code></pre>
  
  <p>but does not when I wrap the second foreach with "div" tags. It saying the item variable does not exist in that case.</p>
  
  <pre><code>@foreach (var group in Model.Groups)
  {
      &lt;div&gt;
      foreach (var item in group.Items)
      {
          &lt;span&gt;@item.Title&lt;/item&gt;
      }
      &lt;/div&gt;
  }
  </code></pre>
  
  <p>I made it work using the following code, but doubt it is the best solution</p>
  
  <pre><code>@foreach (var group in Model.Groups)
  {
      @Html.Raw("&lt;div&gt;");
      foreach (var item in group.Items)
      {
          &lt;span&gt;@item.Title&lt;/item&gt;
      }
      @Html.Raw("&lt;/div&gt;");
  }
  </code></pre>