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?
@{
if(@Model.RootPageName != null)
{
var abstractPage = Content.GetPage<AbstractPage>(@Model.RootPageName);
var url = GenerateUrl(abstractPage);
}
else
{
var url = @Model.ButtonUrl;
}
}
<a href="@url" class="small button">@Model.ButtonText</a>
Just move
url
so it's accessible outside of theif
scope: