使用多角色来控制授权,MembershipExtensions中还有部分未能完全处理
大石头 authored at 2018-03-19 18:52:53
935.00 B
X
@using NewLife.Model;
@using XCode.Membership;
@{
    var user = ViewBag.User as IUser ?? User.Identity as IUser;

    var fact = ObjectContainer.Current.Resolve<IMenuFactory>();

    var item = Model as IMenu;
    var childs = fact.GetMySubMenus(item.ID, user).Where(m => m.Visible);
    var url = item.Url.IsNullOrEmpty() ? "" : Url.Content(item.Url);
}
<li>
    @if (childs.Any())
    {
        <a href="#" class="dropdown-toggle">
            <i class="menu-icon fa fa-caret-right"></i>
            @item.DisplayName
        </a>
    }
    else
    {
        <a href="@url" target="main">
            <i class="menu-icon fa fa-caret-right"></i>
            @item.DisplayName
        </a>

        <b class="arrow"></b>
        <ul class="submenu">
            @foreach (var menu in childs)
            {
                @Html.Partial("_Left_Item", menu);
            }
        </ul>
    }
</li>