Track the current active page, or how to get controller and action names in a view

前端 未结 4 1227
滥情空心
滥情空心 2020-12-31 03:55

I am new in ASP.NET Core. I have a navigation menu and I would like to track the active item. My idea is to use the action and controller names as navigation keys:

<

4条回答
  •  借酒劲吻你
    2020-12-31 04:59

    Use

    var controller = ViewContext.RouteData.Values["Controller"];
    var action = ViewContext.RouteData.Values["Action"];
    
    
    

    PS: Use ToLower() if required

    ViewContext.RouteData.Values["Action"].ToString().ToLower();
    

    Also you can activate your menu by style block

    
    

提交回复
热议问题