I am trying to create my navigator to show a highlight when on certain pages. I’ve got the following:
<li>
@if (Request.Url.AbsoluteUri.ToLowerInvariant().Contains("registration"))
{
@Html.ActionLink("Request an Invite", "index", "registration", null, new { @class = "active" })
}
else
{
@Html.ActionLink("Request an Invite", "index", "registration")
}
</li>
<li>
@if (Request.Url.AbsoluteUri.ToLowerInvariant().Contains("login"))
{
@Html.ActionLink("Login", "index", "login", null, new { @class = "active" })
}
else
{
@Html.ActionLink("Login", "index", "login")
}
</li>
Im sure there is a better way to make this less soupy? Can someone help a beginner?
Thanks
James Woodley
In my opinion to avoid error on potential similar urls you can use
then to make your code smaller I will use an inline condition
I hope you get the idea