ASP.NET MVC: Masterpage: How to set css class on active menu item

前端 未结 5 1405
情书的邮戳
情书的邮戳 2020-12-23 23:25

I have the following menu in my masterpage:

  • <%= Html.ActionLink(\"Employees\",
5条回答
  •  南方客
    南方客 (楼主)
    2020-12-24 00:04

    That's probably the least intensive way of doing it. If you can count on the users to have javascript enabled, I see nothing wrong with this, and have done it myself on occasion.

    Request.Url is the object you are interested in to get the current page on the server side. The suggestion to use window.location.href by tvanfosson isn't bad either if you want to keep it entirely clientside.

    The advantage of using serverside, is that Request.Url has easily accessible parts of the url, such as Request.Url.Host, etc to help with your link-munging needs.

提交回复
热议问题