Navigation menu with highlight in Asp.NET MVC?

后端 未结 7 894
广开言路
广开言路 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:19

    There is probably no MVC special magic that makes this happen.

    I'm sure:

    if( HttpContext.Current.Request.Path == "some some menu url" )
    

    or

    if( ViewContext_Or_ControllerContext.RouteData.Values["controller"] == "some value") 
    

    is used someplace.

    You could put this code in about three different locations ( View ( .aspx ), ViewModel, Custom HtmlHelper ) and they would all require that same bit of code.

提交回复
热议问题