From f51237f9eaba81580486e503e04d3512d2294496 Mon Sep 17 00:00:00 2001 From: Argo-Lenovo Date: Tue, 20 Dec 2016 13:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84HeaderBarModel=E7=A7=BB?= =?UTF-8?q?=E9=99=A4=E4=B8=8D=E7=94=A8=E7=9A=84ShowMenu=EF=BC=8C=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E6=98=AF=E5=90=A6=E9=9C=80=E8=A6=81=E5=88=9D=E5=A7=8B?= =?UTF-8?q?=E5=8C=96=E5=89=8D=E5=8F=B0=E8=8F=9C=E5=8D=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bootstrap.Admin/Controllers/HomeController.cs | 7 +++++-- Bootstrap.Admin/Models/HeaderBarModel.cs | 8 ++------ Bootstrap.Admin/Views/Shared/Header.cshtml | 4 ++-- Bootstrap.DataAccess/MenuHelper.cs | 4 ++-- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/Bootstrap.Admin/Controllers/HomeController.cs b/Bootstrap.Admin/Controllers/HomeController.cs index 615e7889..7bf16f96 100644 --- a/Bootstrap.Admin/Controllers/HomeController.cs +++ b/Bootstrap.Admin/Controllers/HomeController.cs @@ -19,8 +19,11 @@ namespace Bootstrap.Admin.Controllers { var v = new HeaderBarModel(); v.HomeUrl = DictHelper.RetrieveHomeUrl(); - v.ShowMenu = true; - if (v.HomeUrl.StartsWith("~/")) return View(v); + if (v.HomeUrl.StartsWith("~/")) + { + v.Menus = MenuHelper.RetrieveLinksByUserName(User.Identity.Name); + return View(v); + } else return Redirect(v.HomeUrl); } /// diff --git a/Bootstrap.Admin/Models/HeaderBarModel.cs b/Bootstrap.Admin/Models/HeaderBarModel.cs index 140e6ca5..f7097138 100644 --- a/Bootstrap.Admin/Models/HeaderBarModel.cs +++ b/Bootstrap.Admin/Models/HeaderBarModel.cs @@ -16,7 +16,7 @@ namespace Bootstrap.Admin.Models DisplayName = user.DisplayName; UserName = user.UserName; UserID = user.ID; - Menus = MenuHelper.RetrieveLinksByUserName(UserName); + Menus = new List(); } public string UserName { get; protected set; } /// @@ -30,15 +30,11 @@ namespace Bootstrap.Admin.Models /// /// /// - public bool ShowMenu { get; set; } - /// - /// - /// public string HomeUrl { get; set; } /// /// 获得/设置 前台菜单 /// - public IEnumerable Menus { get; private set; } + public IEnumerable Menus { get; set; } /// /// 获得/设置 用户头像地址 /// diff --git a/Bootstrap.Admin/Views/Shared/Header.cshtml b/Bootstrap.Admin/Views/Shared/Header.cshtml index 29f6dbd0..821f88f1 100644 --- a/Bootstrap.Admin/Views/Shared/Header.cshtml +++ b/Bootstrap.Admin/Views/Shared/Header.cshtml @@ -7,7 +7,7 @@ @Model.Title - @if (Model.Menus.Count() > 0 && Model.ShowMenu) + @if (Model.Menus.Count() > 0) { } - @if (!Model.ShowMenu && (LgbPrincipal.IsAdmin(User.Identity.Name) || User.IsInRole("Administrators"))) + @if (LgbPrincipal.IsAdmin(User.Identity.Name) || User.IsInRole("Administrators")) {
    diff --git a/Bootstrap.DataAccess/MenuHelper.cs b/Bootstrap.DataAccess/MenuHelper.cs index 16963bfa..133ad983 100644 --- a/Bootstrap.DataAccess/MenuHelper.cs +++ b/Bootstrap.DataAccess/MenuHelper.cs @@ -83,9 +83,9 @@ namespace Bootstrap.DataAccess return root; } /// - /// + /// 通过当前用户名获得前台菜单 /// - /// + /// 当前登陆的用户名 /// public static IEnumerable RetrieveLinksByUserName(string userName) {