• 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     }

    2、前台cshtml使用

    1 <div class="collapse navbar-collapse  pull-right">
    2                 <ul class="nav navbar-nav">
    3                     <li>@Html.MenuLink("育儿宝典", "YuErBaoDian", "Home")</li>
    4                     <li>@Html.MenuLink("关于我们", "About", "Home")</li>
    5                     <li>@Html.MenuLink("联系我们", "Contact", "Home")</li>
    6                 </ul>
    7 </div>

     

    作者:Tommy
    出处:https://www.cnblogs.com/XL-Tommy/
    本文版权归作者和博客园所有,欢迎转载,转载请标明出处。 
    如果您觉得本篇博文对您有所收获,觉得还算用心,请点击右下角的 [推荐],谢谢!

  • 相关阅读:
    提高php代码效率的几点
    jquery各种操作复选框(全选、全不选、自动勾选、反选……)
    封装PDO单例模式类
    Git常用命令
    简化版的sqlserver分页
    Sql Server 数据分页
    Linux 下动态链接库搜索路径问题
    mysqlperformanceblog
    vim 退格键(backspace)不能用
    Linux vi/vim 编辑命令总结
  • 原文地址:https://www.cnblogs.com/XL-Tommy/p/10144713.html
Copyright © 2020-2023  润新知