ASP.NET MVC高亮显示当前页面菜单

1、创建MvcHtmlExtension扩展类

1 public static class MvcHtmlExtension 2 { 3 public static MvcHtmlString MenuLink(this HtmlHelper helper, string text, string action, string controller) 4 { 5 var routeData = helper.ViewContext.RouteData.Values; 6 var currentController = routeData["controller"]; 7 var currentAction = routeData["action"]; 8 if (String.Equals(action, currentAction as string, StringComparison.OrdinalIgnoreCase) && 9 String.Equals(controller, currentController as string, StringComparison.OrdinalIgnoreCase)) 10 { 11 return helper.ActionLink(text, action, controller, null, new { @class = "menua" }); 12 } 13 return helper.ActionLink(text, action, controller); 14 } 15 }

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zysgfp.html