title: What is the scope of variables in Razor MVC 3
body: <p>I am having problems with variable scope for <code>myClient</code> in my Razor code. I am sure the solution is simple. Basically I am referencing it in a seperate <code>@{}</code> block which perhaps is causing the issue, but it seems unless I do this I get the <code>if..{}</code> code in the HTML.</p>
  
  <pre><code>@{
  int i = 0;
  foreach (var item in Model.Clients)
      {
          Int32 myId = Convert.ToInt32(item.DBID);
          var myClient = db.Client.Where(c =&gt; c.Id == myId).First();
      &lt;td&gt;
          &lt;table class="inner"&gt;
          &lt;tr&gt;&lt;th&gt;
              @string.Format(
                  "{0} {1} {2}",
                  myClient.Title,
                  myClient.Initials,
                  myClient.LastName)
  
                  @{
                      if (myClient.Type!="Primary")
                      {
                          @Html.ActionLink(
                              "Delete", 
                              "Delete", 
                              "ClientBackground", 
                              new { id=item.ID }, null)
                      }
                   }
              &lt;/th&gt;&lt;/tr&gt;
          }
          &lt;table&gt;
  </code></pre>
  
  <p>My code cannot reference <code>myClient.Type</code>. If I remove the surrounding <code>@{}</code> then I get the c# code in the HTML.</p>
  
  <p>Something simple I know, but I am failing to see it.</p>
  
  <p>Any help hugely appreciated.</p>
  
  <p>EDIT: Table closed off. </p>