目录
3.3将控制器原本引用的 Controller改为BaseController
1、创建MVC
2、下载Layui
地址:Layui - 极简模块化前端 UI 组件库(官方文档)
将文件放在根目录
3、修改模板页
3.1 修改_Layout.cshtml页面
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>后台管理系统 - My ASP.NET Application</title>
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="~/layui/css/layui.css">
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
<script src="~/Scripts/modernizr-2.8.3.js"></script>
</head>
<body class="layui-layout-body" >
<div class="layui-layout layui-layout-admin">
<div class="layui-header">
<div class="layui-main">
<div class="layui-logo">LOGO</div>
<ul class="layui-nav layui-layout-right">
<li class="layui-nav-item ">
<a href="javascript:;">登陆人: @Session["username"]</a>
<dl class="layui-nav-child">
<dd><a href="javascript:;">Your Profile</a></dd>
<dd><a href="javascript:;">重置密码</a></dd>
<dd><a href="javascript:;">退出</a></dd>
</dl>
</li>
</ul>
</div>
</div>
<div class="layui-side layui-bg-black">
<div class="layui-side-scroll">
<ul class="layui-nav layui-nav-tree" lay-filter="navSlide">
@Html.Raw(ViewBag.MenuItems)
</ul>
</div>
</div>
<div class="layui-body">
<div class="layui-fluid">
@RenderBody()
@RenderSection("content", false)
</div>
</div>
</div>
<script src="~/layui/layui.js"></script>
</body>
</html>
3.2创建侧边导航-BaseController控制器
public class BaseController : Controller
{
protected override void Initialize(System.Web.Routing.RequestContext requestContext)
{
base.Initialize(requestContext);
SetMenu();
}
private void SetMenu()
{
StringBuilder sb = new StringBuilder();sb.AppendFormat("<li class=\"layui-nav-item {0}\">", "aaaa");
sb.AppendFormat("<a class='layui-icon {0}' href=\"{1}\">    {2}</a>", "layui-icon-menu-fill", "/Home/Index", "首页");//设置好路由,方便跳转页面
sb.AppendFormat("</li>");sb.AppendFormat("<li class=\"layui-nav-item {0}\">", " ");
sb.AppendFormat("<a class='layui-icon {0}' href=\"{1}\">    {2}</a>", "layui-icon-set", "/Home/About", "学生管理");
sb.AppendFormat("</li>");sb.AppendFormat("<li class=\"layui-nav-item {0}\">", " ");
sb.AppendFormat("<a class='layui-icon {0}' href=\"{1}\">    {2}</a>", "layui-icon-user", "/Home/Contact", "学生管理");
sb.AppendFormat("</li>");
ViewBag.MenuItems = sb.ToString();
}
}