ASP.NET MVC - Current Page highlighting in navigation

前端 未结 5 485
星月不相逢
星月不相逢 2020-12-08 11:46

I\'m wondering how is it possible to add a CSS Class to the current page in your navigation when using ASP.NET MVC 3? Here is my navigation in my _Layout.cshtml file:

<
5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-08 12:11

    In my case,assume I have a Home page and a menu.

    Add a ViewBag.Active as a placeholder in Home page like this:

    @{
       ViewBag.Title = "Home";
       ViewBag.Active = "Home";
    }
    

    Then place it to your li class as a condition to active it or not:

     
  • @ViewBag.Title
提交回复
热议问题