title: How to mix HTML and C# Code in MVC3 with Razor?
body: <p>I am trying to display a list of items that should toggle a class for styling purposes. The idea is to create a foreach loop that will cycle through all the <code>myObj</code> in the Model.</p>
  
  <p>I tried the following code which does not work (because I'm doing it wrong)</p>
  
  <pre><code>@{ int i = 2;
     foreach(var myObj in Model)
     {
          if (i % 2 == 0)
          {
              &lt;div class="class1"&gt;
          }
          else
          {
              &lt;div class="class2"&gt;
          }
          Html.Partial(...);
          &lt;/div&gt;
           i += 1;
     }     
  }
  </code></pre>
  
  <p>What is the proper way to accomplish this?</p>
  
  <p><strong>Update</strong>
  <br>
  I also tried the following code that, although compiles, does not render any HTML code within (and I'm sure there are objects in Model).</p>
  
  <pre><code>@{ int i = 2;
     foreach(var myObj in Model)
     {
          if (i % 2 == 0)
          {
              @:&lt;div class="class1"&gt;
          }
          else
          {
              @:&lt;div class="class2"&gt;
          }
          Html.Partial(...);
          @:&lt;/div&gt;
  
          i += 1;
     }
  
  }
  </code></pre>
  
  <p>This is the partial class being called</p>
  
  <pre><code>&lt;div class="class"&gt;
      &lt;div class="class2"&gt;
          @if (string.IsNullOrEmpty(var))
          {
              @var2
          }
          else
          {
              @var
          }
      &lt;/div&gt;
      &lt;div class="class3"&gt;
          @var3
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="class4"&gt;
      &lt;p&gt;var4&lt;/p&gt;
      &lt;ul class="class5"&gt;
          &lt;li&gt;element1&lt;/li&gt;
          &lt;li&gt;element2&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I'm sorry I can't post the actual names and variables.</p>