zoukankan      html  css  js  c++  java
  • 实现:左边为菜单导航,当一个菜单中包含多个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,让其根据权限判断要显示的页面很好地解决了这个问题。
      

  • 相关阅读:
    nginx rewrite 伪静态重写学习笔记
    正则表达式相关知识
    rpm的含义
    find命令的使用
    chmod的运用方式
    [GO]数组的比较和赋值
    [GO]二维数组的介绍
    [GO]变量内存和变量地址
    [GO]给导入包起别名
    阿里云负载均衡SLB 七层https协议 nginx 获取真实IP
  • 原文地址:https://www.cnblogs.com/sunshineground/p/4331935.html
Copyright © 2011-2022 走看看