title: Cannot access conditional Razor variable as href
body: <p>I have a razor view that generates a url based on some items returned by the model. When I create a url variable without any if statements, the url variable can be found and used as an href. However, when I have this code (using if statements) it says: "The name 'url' does not exist in the current context". How can I make this work?</p>
  
  <pre><code>       @{
      if(@Model.RootPageName != null)
      {     
           var abstractPage = Content.GetPage&lt;AbstractPage&gt;(@Model.RootPageName);
           var url = GenerateUrl(abstractPage);
      }
      else
      {
          var url = @Model.ButtonUrl;
  
      }
   }
  
  &lt;a href="@url" class="small button"&gt;@Model.ButtonText&lt;/a&gt;
  </code></pre>