Navigation menu with highlight in Asp.NET MVC?

后端 未结 7 897
广开言路
广开言路 2021-02-14 15:31

It\'s a simple question. How did stackoverflow do their menu in Asp.net MVC, with highlight on what page we are on.

7条回答
  •  孤独总比滥情好
    2021-02-14 16:11

    The best way - create MVC helper (see previous answers) But if you don't want to do it and want to do quickly - remember about new feature in MVC 4.0 with set attributes of html tags (attribute will be avoid if it's set to null):

            @{
                string currentAction = ViewContext.RouteData.Values["action"].ToString().ToLower();
    
                string classUpcomingTime = null;
                string classArchive = null;
                string classReporting = null;
    
                switch (currentAction)
                {
                    case "upcomingtime":
                        classUpcomingTime = "active";
                        break;
                    case "archive":
                        classArchive = "active";
                        break;
                    case "reporting":
                        classReporting = "active";
                        break;
                }
    
                
            }
    

提交回复
热议问题