修正菜单导航Model,移除通用的代码

This commit is contained in:
Argo-Lenovo 2016-11-03 19:52:35 +08:00
parent 84a2b35373
commit 296f246e45
2 changed files with 14 additions and 33 deletions

View File

@ -1,4 +1,5 @@
using Bootstrap.Admin.Models; using Bootstrap.Admin.Models;
using Bootstrap.DataAccess;
using System.Web.Mvc; using System.Web.Mvc;
namespace Bootstrap.Admin.Controllers namespace Bootstrap.Admin.Controllers
@ -14,9 +15,7 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns> /// <returns></returns>
public ActionResult Index() public ActionResult Index()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Index");
v.ShowMenu = "hide";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
/// <summary> /// <summary>
@ -25,10 +24,7 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns> /// <returns></returns>
public ActionResult Users() public ActionResult Users()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Users");
v.ShowMenu = "hide";
v.Menus[1].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
/// <summary> /// <summary>
@ -37,10 +33,7 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns> /// <returns></returns>
public ActionResult Groups() public ActionResult Groups()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Groups");
v.ShowMenu = "hide";
v.Menus[3].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
/// <summary> /// <summary>
@ -49,35 +42,23 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns> /// <returns></returns>
public ActionResult Dicts() public ActionResult Dicts()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Dicts");
v.ShowMenu = "hide";
v.Menus[4].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
public ActionResult Roles() public ActionResult Roles()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Roles");
v.ShowMenu = "hide";
v.Menus[2].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
public ActionResult Menus() public ActionResult Menus()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Menus");
v.ShowMenu = "hide";
v.Menus[0].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
public ActionResult Logs() public ActionResult Logs()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Logs");
v.ShowMenu = "hide";
v.Menus[6].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
/// <summary> /// <summary>
@ -95,10 +76,7 @@ namespace Bootstrap.Admin.Controllers
/// <returns></returns> /// <returns></returns>
public ActionResult Profiles() public ActionResult Profiles()
{ {
var v = new NavigatorBarModel(); var v = new NavigatorBarModel("~/Admin/Profiles");
v.ShowMenu = "hide";
v.Menus[5].Active = "active";
v.HomeUrl = "~/Admin";
return View(v); return View(v);
} }
} }

View File

@ -1,4 +1,5 @@
using Bootstrap.DataAccess; using Bootstrap.DataAccess;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -6,10 +7,12 @@ namespace Bootstrap.Admin.Models
{ {
public class NavigatorBarModel : HeaderBarModel public class NavigatorBarModel : HeaderBarModel
{ {
public NavigatorBarModel() public NavigatorBarModel(string url)
{ {
Menus = MenuHelper.RetrieveMenus().ToList(); Menus = MenuHelper.RetrieveMenus().ToList();
Menus.ForEach(m => m.Active = null); Menus.ForEach(m => m.Active = m.Url.Equals(url, StringComparison.OrdinalIgnoreCase) ? "active" : "");
HomeUrl = "~/Admin/Index";
ShowMenu = "hide";
} }
/// <summary> /// <summary>
/// ///