title: Can't seem to conditionally create a new table row using Razor's foreach and if statements?
body: <p>I want a loop to dynamically create a table up to 2 columns wide, and then increase the number of rows until there are no entries left in the list.  Sounds easy, and I came up with this:</p>
  
  <pre><code>&lt;table&gt;
                      &lt;tr&gt;
                          @{ var i = 0; }
                          @foreach (var tm in Model.TeamMembers)
                          {
                              &lt;td&gt;@tm.FirstName @tm.LastName @tm.Role&lt;/td&gt;
  
                              if(++i % 2 == 0)
                              {
                                  &lt;/tr&gt;
                                  &lt;tr&gt;
                              }
                          }
                      &lt;/tr&gt;
                  &lt;/table&gt;
  </code></pre>
  
  <p>But I get errors stating } expected both for the for loop and the if statement.  If I change the  tags to something else (like  for instance) it works fine.  </p>
  
  <p>My guess is it's trying to validate the end of the row, sees it and decides the loop must be over?  How can I make it NOT do that, or do I need to put the entire table inside the loop with a bunch of messy conditionals? :(</p>