【问题标题】:How to use " UserPanel Layout " in " Main Layout "?如何在“主布局”中使用“用户面板布局”?
【发布时间】:2021-09-15 01:15:33
【问题描述】:
我在 User_Panel 区域中创建了一个布局(“_UserLayout.cshtml”):
Click to see Image
就像我们在 Admin_Panel 中所做的一样。 (侧边栏中的每个按钮都有一个 ActionResult )
但问题是我希望此布局位于网站的主要布局内。也就是说,用户面板布局在网站的内容部分:
Click to see Image
一模一样。
我如何在 Asp.Net Core 中做到这一点?
我在用户面板区域的“_ViewStart.cshtml”中使用了主布局,但是在所有视图中每次都重复用户布局(例如:侧边栏)没有意义......
很多网站的用户面板是这样的:
Click to see Image
最好的方法是什么?
非常感谢
【问题讨论】:
标签:
asp.net
asp.net-mvc
asp.net-core
asp.net-core-mvc
【解决方案1】:
您可以在任何布局页面中使用其他布局作为Layout。例如:
网站主布局(_BaseLayout.cshtml):
<html>
<head>...</head>
<body>
@RenderBody()
</body>
</html>
管理布局 (_AdminLayout.cshtml):
@{
Layout = "_BaseLayout";
}
<!-- Put markups which are common to all admin pages -->
@RenderBody()
用户面板布局 (_UserLayout.cshtml)
@{
Layout = "_BaseLayout";
}
<!-- Put markups which are common to all user pages pages (side panel etc) -->
@RenderBody()
您可以像这样构建布局。然后在所有用户页面中使用它,例如:
一个示例用户页面(UserAccount.cshtml)
@{
Layout = "_UserLayout";
}
<!-- page markups -->