如何从不同的区域设置相同的布局
本文关键字:设置 布局 区域 | 更新日期: 2023-09-27 18:03:20
如何在MVC 6 Vnext中设置不同区域的相同布局,
我正在使用_ViewImports。cshmlt和_ViewStart。每个区域的CSHTML
在_ViewStart。cshtml
@{
Layout = "_/Views/Shared/_Layout.cshtml";
}
和_ViewImports.cshtml
@using Cross2Enterprise.Administrador
@using Cross2Enterprise.Administrador.Models
@using Microsoft.Framework.OptionsModel
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
我想这就是你的场景:
- ASP。。Core w/MVC
- 使用
'Areas
文件夹 - 你想在一个位置设置所有区域使用的模板
要做到这一点,有以下项目布局:
'Areas'Home
'Areas'Home'Controllers
'Areas'Home'Views
'Areas'_ViewStart.cshtml
'Views
'Views'Shared'
'Views'Shared'_Layout1.cshtml
'Views'Shared'_Layout2.cshtml
然后在文件'Areas'_ViewStart.cshtml
中,您可以有以下内容:
@{
Layout = "_Layout1";
}
这将使所有区域的所有视图使用'Views'Shared'_Layout1.cshtml
。
注意:您可以NOT将_ViewStart.cshtml
放在以下位置:
'Views'_ViewStart.cshtml
'Views'Shared'_ViewStart.cshtml
注意:您可以将_ViewStart.cshtml
放在以下位置:
'Areas'Home'_ViewStart.cshtml
注意:这也适用于_ViewImports.cshtml
我只是抛弃了显而易见的东西…你试过……吗?(我只看过一些关于VNext的东西)
Layout = "~/Views/Shared/_Layout.cshtml";