title: Razor HTML Conditional Output
body: <p>I have a list of items I want to output as the contents of a main  (the main  in not included below). Each Item has 3 attributes: a Section Name, a Label and a Value. Each item is enclosed in a  and everytime the Section Name changes I have to open a  (and close the previous one, if any). I'm using a Razor view with this code:</p>
  
  <pre><code>@foreach (LocalStorageItem lsi in Model) { 
      string fld_name = "f_" + lsi.ItemName;
      if (lsi.SectionName != sn) {
          if (sn != "") { 
              Html.Raw("&lt;/fieldset&gt;"); 
          }
          sn = lsi.SectionName;
          &lt;h2&gt;@sn&lt;/h2&gt;
          Html.Raw("&lt;fieldset&gt;");              
      }
          &lt;div class="row"&gt;
              &lt;div class="ls_label"&gt;@lsi.ItemName&lt;/div&gt;
              &lt;div class="ls_content" name="@fld_name" id="@fld_name"&gt;.&lt;/div&gt;
          &lt;/div&gt;        
   }
   @if (Model.Count != 0) {
      Html.Raw("&lt;/fieldset&gt;");
   }
  </code></pre>
  
  <p>The problem is: each time the Section Name changes no fieldset tag (open and/or close) is generated. Where am I wrong? If I don't use Html.Raw (or @: as an alternative) the VS2010 parser signals an error.</p>