I have a extension method which is as follows:
public static MvcHtmlString IsSelected(this HtmlHelper htmlHelper, string controller, string action)
{
var routeData = htmlHelper.ViewContext.RouteData;
var routeAction = routeData.Values["action"].ToString();
var routeController = routeData.Values["controller"].ToString();
return controller == routeController && action == routeAction
? MvcHtmlString.Create("is-selected")
: MvcHtmlString.Create("is-not-selected");
}
as you can see it's fairly straight forward and does not do anything fancy. This is called in the _Layout
as:
<li class="@Html.IsSelected("Common", "Active")">@Html.ActionLink("Active", "Active", "Common")</li>
<li class="@Html.IsSelected("Common", "Completed")">@Html.ActionLink("Completed", "Completed", "Common")</li>
This then adds the relevant class to the li
item which is styled in the css as:
.is-selected {
border-bottom: 3px solid;
}
The end result is that the is-selected
navigation item has a border for a better ux. This all works fine. However, on the Active
and Completed
views have an overview of bunch of items where the user can click on each item and get a more in depth detail. On click of the item the user is navigated to Common/ItemDetails/itemId
Now the issue I am facing is that when the user clicks on an item in either from Active or Completed view neither of the li
items contain a border. Can someone tell how I can achieve this please.
The desired behaviour I am after is if the user clicks on an item from Active
view and gets navigated to Common/ItemDetails/itemId
then the Active
li
has a border and the same behaviour for Completed
view