title: The closing braces of my C# code are not recognized in a Razor partial view
body: <p>I am working on a asp.net mvc 3 application. I use Razor for my views. I had this problem  friday and thought I have fixed it but now I see that it was just some private case where the things worked for some reason.</p>
  
  <p>I have a table with four columns, but each row may have different number of fields in one cell so I'm working on some sort of algorithm which will fill my cells with all the info that belong to them. This is what I have now :</p>
  
  <pre><code>@{
      int tempColumn = 1;    
  }
  
  &lt;tr&gt;
  @foreach (var field in Model)
  {   
      if (field != null)
      {   
          &lt;td&gt;    
          @for (int i = 0; i &lt; field.Count; i++)
          {
              if (field[i].ColumnNo == tempColumn)
              {
                  @field[i].QuestionText;
                  @field[i].FieldValue;
              }
              else if (field[i] != null)
              {
                  tempColumn++;
                  @:&lt;/td&gt;
                  @:&lt;td&gt;
                  @field[i].QuestionText;
                  @field[i].FieldValue;
              }
          }
      }
      @:&lt;/td&gt;      
  }
  &lt;/tr&gt;
  </code></pre>
  
  <p>Basically the idea is that no matter how many pairs of <code>@field[i].QuestionText;</code> / <code>@field[i].FieldValue;</code> I have I will always have an opening <code>&lt;td&gt;</code> tag at the begining of the row and closing <code>&lt;/td&gt;</code> tag at the end of the row. I have problems with the algorithm too but before I fix the issue with the not recognized closing bracelets I can't continue. So what is the error - when I try and run this code in debug mode I get this error : </p>
  
  <blockquote>
    <p>The foreach block is missing a closing "}" character.  Make sure you
    have a matching "}" character for all the "{" characters within this
    block, and that none of the "}" characters are being interpreted as
    markup.</p>
  </blockquote>
  
  <p>But when I go to the code itself I get the same error about the <code>if</code> block and the <code>for</code> block. I thought that inserting the HTML <code>&lt;td&gt;</code> and <code>&lt;/td&gt;</code> tags using this syntax - <code>@:</code> will keep the sructure of my C# code and just add the tags where I want them, but from what I think it seems that some reason at least one <code>&lt;td&gt;</code> or <code>&lt;/td&gt;</code> tag is interpreted so that everything after it is recognized as HTML markup and not C# code. So what is the proper way to insert HTML markup in a C# method, or if the error is cause from something else - what could it be?</p>
  
  <p>P.S</p>
  
  <p>Any help about the algorithm would be appreciated though it's not the topic of this question.</p>