我是MVC的初学者,并试图将Admin重定向到_Layout - admin.cshtml登录成功后,因为我在管理navbar中有不同的选项。我已经登录并将布局重定向到_Layout - admin.cshtml成功。但是,当我点击图库选项时,我的布局再次移动到之前的_Layout.cshtml。这是不正确的。在mvc登录后将管理员重定向到布局
任何人都可以建议我,我该如何解决这个问题?
_layout - admin.cshtml
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - SS General Trading</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
@RenderPage("~/Views/Shared/Navbar-admin.cshtml")
<div>
@RenderBody()
<hr />
<footer style="margin-top:-50px; z-index:999" class="site-footer">
<div class="row">
<div style="border-right:groove" class="col-md-4">
</div>
<div style="border-right:groove" class="col-md-4">
</div>
<div class="col-md-4">
</div>
</div>
</footer>
</div>
@Scripts.Render("~/bundles/jquery")
@Scripts.Render("~/bundles/bootstrap")
@RenderSection("scripts", required: false)
</body>
</html>
导航栏,admin.cshtml
@{ Layout = null; }
<!DOCTYPE HTML>
<html lang="en">
<head>
-------- some code
</head>
<body>
<!-- header-top -->
<div class="header-top">
------- some code
<div class="top-nav">
<nav class="navbar navbar-default">
<div class="container">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
Menu
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="home-icon"><a href="index.html"><span class="fa fa-home" aria-hidden="true"></span></a></li>
<li>@Html.ActionLink("News", "Index", "News_Events")</li>
<li>@Html.ActionLink("Gallery", "Index", "Galleries")</li>
@Html.Partial("_LoginPartial")
</ul>
</div>
<div class="clearfix"> </div>
</div>
</nav>
</div>
</div>
<!-- //container -->
</div>
</body>
</html>
_ViewStart.cshtml
@{
if (this.User.IsInRole("Admin"))
{
Layout = "~/views/shared/_layout - admin.cshtml";
}
else
{
Layout = "~/Views/Shared/_Layout.cshtml";
}
}
你为什么试图重定向到布局? – CodeCaster
你想要做什么? –
我想在管理员登录后重定向我的布局,因为管理员navbar bcz admin navbar在我的情况下是不同的。 –