Can i shorten this to one line? I have tried various ways but can\'t quite get it right.
@if(SiteMap.CurrentNode.Title == \"Contact\")
{
@:
The shortest possible way to do is like:
@(SiteMap.CurrentNode.Title == "Contact" ? "<div class='contact'>" : "")
or
@(SiteMap.CurrentNode.Title == "Contact" ? @"<div class=""contact"">" : "")
or even shorter if you don't repeat your html code
<div class="@(SiteMap.CurrentNode.Title == "Contact" ? "contact" : "")">
There might be an even simpler solution but this should work:
@Html.Raw((SiteMap.CurrentNode.Title == "Contact") ? "<div class='contact'>" : "")
Another way would be:
@if(SiteMap.CurrentNode.Title == "Contact") { <text><div class="contact"></text> }
I personally find it more readable than the ternary operator, but this is personal
This will work
Razor Syntax
@(SiteMap.CurrentNode.Title == "Contact" ? "<div class='contact'>")