title: Question about nested code block declarations in Razor
body: <p>I've recently upgraded a project from MVC 1 to MVC 3 and now I'm trying out Razor.</p>
  
  <p>In one View, I have a foreach code block, but the nested if statement does not seem to want the @ in front of it.</p>
  
  <p>My original code was:</p>
  
  <pre><code>@foreach(var r in Model.Results) 
  {
      string css = r.Result.Count() &gt; 0 ? "fail" : "pass";
  
      &lt;p class="@css"&gt;&lt;strong&gt;@r.Description&lt;/strong&gt;&lt;/p&gt;
  
      @if(r.Result.Count() &gt; 0) 
      {
          &lt;p&gt;Count: @r.Result.Count()&lt;/p&gt;
          &lt;table&gt;
              &lt;thead&gt;
                  &lt;tr&gt;
                      &lt;th&gt;ID&lt;/th&gt;&lt;th&gt;Title&lt;/th&gt;&lt;th&gt;Description&lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
              @foreach(var e in r.Result) {
                  &lt;tr&gt;&lt;td&gt;@e.Id&lt;/td&gt;&lt;td&gt;@e.Title&lt;/td&gt;&lt;td&gt;@e.Description&lt;/td&gt;&lt;/tr&gt;
              }
              &lt;/tbody&gt;
          &lt;/table&gt;
      }
  }
  </code></pre>
  
  <p>I'll get a runtime error with @if that says: Unexpected "if" keyword after "@" character.  Once inside code, you do not need to prefix constructs like "if" with "@".</p>
  
  <p>If I remove the @ the code runs fine. I expected to need the @ because of the HTML immediately preceding it. What confuses me more is that I do need the @ before the nested foreach. What are the rules in play here?</p>