title: Using If statement in a MVC Razor View
body: <p>In the following code,</p>
  
  <p>If I use "@If" statement ,I get the following compile code error as " The name 'grid' does not exist in the current context.  </p>
  
  <pre><code>@if (Model.SModel != null)
  
  {
  
  @{ 
      WebGrid grid = new WebGrid(Model.SModel);
  
   }
  
   }
  
   else
   {
  }
  
  @grid.GetHtml()
  </code></pre>
  
  <p>,</p>
  
  <p>But the code compiles without the "If" statement.For example</p>
  
  <pre><code>@{ 
      WebGrid grid = new WebGrid(Model.SModel);
  
  }
  @grid.GetHtml().
  </code></pre>
  
  <p>What is the syntactical error in using If else statement</p>