ASP.NET MVC Menu Selected Item

前端 未结 7 1502
夕颜
夕颜 2021-01-30 18:29

OK new to MVC. I had asked this question earlier and got an answer but I am wondering if there is a simpler solution.

Say I have a master page with a menu laid out as an

7条回答
  •  轮回少年
    2021-01-30 18:43

    Beside all other solutions you can use this approach to load menus dynamically from Database and make the selected menu active and keep the status across the website.

    in the Layout page:

    
    
    @{Html.RenderPartial("_MenuPartial"); }
    @RenderBody()

    Then your partial view contains :

    
    

    To activated the clicked menu, you need a script in the partial view. Also 'active' class in nothing but changing the background color in the CSS.

    
    
                                     
                  
提交回复
热议问题