title: How can I make an unordered list appear within a foreach loop in MVC3 Razor?
body: <p>I have the following code:</p>
  
  <pre><code>@foreach (Content topic in Model.Topics)
  {
      if (topic.RowKey.Substring(2, 2) == "00")
      {
          &lt;h3&gt;@topic.RowKey.Substring(0, 2).TrimStart('0') - @Html.Raw(topic.Title)&lt;/h3&gt;
      }
      else
      {
          &lt;p&gt;@String.Format("{0}.{1}",topic.RowKey.Substring(0, 2).TrimStart('0'),topic.RowKey.Substring(2, 2).TrimStart('0').PadLeft(1, '0')) - @Html.Raw(topic.Title)&lt;/p&gt;
      }
  }
  </code></pre>
  
  <p>My input data (value of topic.RowKey) looks like this:</p>
  
  <pre><code>0100 &lt;- This is topic 1
  0101 &lt;- This is topic 1.1
  0102 &lt;- This is topic 1.2
  0103 &lt;- This is topic 1.3
  0200 &lt;- This is topic 2
  0201 &lt;- This is topic 2.1
  etc....
  </code></pre>
  
  <p>This works but what I would really like to do is to have an h3 heading every time the first two digits of the RowKey change and then between then and then next h3 heading I would like to have an unordered list instead of just <code>&lt;p&gt;xxx&lt;/p&gt;</code>. I have tried lots of different combinations of things but nothing works. Is this even possible to do with Razor? Where I had huge problems was how can I get the <code>&lt;ul&gt;</code> and <code>&lt;/ul&gt;</code>s to appear correctly? I know I can put a <code>&lt;ul&gt;</code> after the <code>&lt;h3&gt;</code> but how can I place the <code>&lt;/ul&gt;</code>?</p>