Highlight link from current page

Asked

Viewed 384 times

1

I am implementing a menu in the header of my page. As the user clicks on the buttons in this menu, the page is rendered just below. I would like to highlight in the menu the button referring to the current user page.

I’m calling it that:

<li>
    <a href="@Url.Action("Index", new { controller = "Informativo" })" title="Informativo"> Inf. </a>
</li> 
  • Have you ever tried to do anything? Would you have some code to direct you?

  • I call them this way: <li> <a href="@Url.Action("Index", new { controller = "Informative" })" title="Informative"> Inf. </a> </li>

1 answer

3

In a system I did here, I used the @section Scripts to set a small action to add a class active in a given item, which highlights the item.

@section scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $("#item-qualquer").toggleClass("active");
        });
    </script>
}

This can be done programmatically, replacing the #item-qualquer by identifying Action and Controller, for example:

@section scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            $("#" + @ViewContext.RouteData.Values["action"]).toggleClass("active");
        });
    </script>
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.