• 实现:左边为菜单导航,当一个菜单中包含多个Tabs,并且不同的Tab要根据权限的不同显示。


    1.前台代码

    //当点击左侧菜单时,将访问Controller中的Home方法,这样就会根据用户权限的不同,通过后台的判断来决定显示的页面
    <li class="@(ViewBag.SelectedNavIndex == NavMenuCatalog.StudentContacts ? "active" : string.Empty)"> @(Html.NavListActionLink<ContactController>("Student Contacts", c => c.Home(), "icon-list", (bool)(ViewBag.SelectedNavIndex == NavMenuCatalog.StudentContacts))) </li>

    2.后台代码

    //在Controller中创建一个Home方法,根据权限的不同让其跳转到不同的Action,从而展现不同的页面
    public
    ActionResult Home() { if (User.PortalIdentity.AuthorizedActions.Any(x => x == ActionLevelSecurity.StudentAddress.GetStringValue())) { return this.RedirectToAction(c => c.StudentAddress()); } if (User.PortalIdentity.AuthorizedActions.Any(x => x == ActionLevelSecurity.ManageContact.GetStringValue())) { return this.RedirectToAction(c => c.Select()); } return new EmptyResult(); }

    3.总结

      问题:

        点击该菜单时,默认会显示第一个Tab,如果此时没有Home这个Action,而是将前台代码中指定为一个具体的Action,例如c => c.StudentAddress(), 当有的用户没有StudentAddress的权限时,默认要显示第二个Tab,这个时候页面显示就不正确。

      技巧:

        在Controller中加入一个Home Action,让其根据权限判断要显示的页面很好地解决了这个问题。
      

  • 相关阅读:
    腾讯云Windows Server下nodejs websocket ssl配置
    Windows下运行MapReduce程序出现Could not locate executable nullwinutils.exe in the Hadoop binaries.
    2.4寒假学习记录
    2.3寒假学习记录
    2.2寒假记录
    2.1日寒假学习记录
    DFA敏感词过滤实现
    手机号和邮箱合法性验证+焦点事件
    复选框显示隐藏
    table+分页+模糊查询
  • 原文地址:https://www.cnblogs.com/sunshineground/p/4331935.html
Copyright © 2020-2023  润新知