razor

Shorten this if statement in Razor to one line


Can i shorten this to one line? I have tried various ways but can't quite get it right.

@if(SiteMap.CurrentNode.Title == "Contact")
{
    @:<div class="contact">
}

Solution

  • There might be an even simpler solution but this should work:

    @Html.Raw((SiteMap.CurrentNode.Title == "Contact") ? "<div class='contact'>" : "")