Adding “active” tag to navigation list in an asp.net mvc master page

后端 未结 15 1765
渐次进展
渐次进展 2020-12-12 13:31

In the default asp.net mvc project, in the Site.Master file, there is a menu navigation list:

15条回答
  •  醉梦人生
    2020-12-12 14:07

    In MVC 3 Razor View Engine, you can do it as:

    @{string ctrName = ViewContext.RouteData.Values["controller"].ToString();}
    
    
    

    My sample worked when I have two pages as: Home/About and its controller has same name Index, so I get controller Name for distinction insteed of action. If you want to get action, just replace with following:

    @{string ctrName = ViewContext.RouteData.Values["action"].ToString();}
    

提交回复
热议问题