我想知道在使用ASP.NET MVC 3時,如何將CSS類添加到導航中的當前頁面?這是我在我的_Layout.cshtml文件導航:ASP.NET MVC - 導航中的當前頁面高亮顯示
<p>@Html.ActionLink("Product Search", "Index", new { controller = "Home" }, new { @class = "current" })
| @Html.ActionLink("Orders", "Index", new { controller = "Orders" })
| @Html.ActionLink("My Account", "MyAccount", new { controller = "Account" })
| @Html.ActionLink("Logout", "LogOff", new { controller = "Account" })</p>
正如你可以看到我在與具有CSS類「當前」適用於它的第一個導航4個鏈路,我想成爲能夠根據用戶所處的頁面將此類添加/刪除到我的導航中的不同鏈接。這可能嗎?
乾杯
謝謝,標記爲答案,因爲我覺得這是做到這一點的最佳方式,更清晰的剃刀視圖和代碼重用性 – CallumVass 2014-07-28 07:32:17
對於擴展'HtmlHelper.ActionLink()',添加[LinkExtensions]的命名空間(https://msdn.microsoft.com/en-us/library/system.web.mvc.html.linkextensions.aspx),如下所示: '使用System.Web.Mvc.Html;' – Mike 2015-09-28 17:02:46