如何在 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"
最佳答案
我认为这是你的场景:
- 带有 MVC 的 ASP.NET Core
- 使用
\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";
}
这将使所有区域中的所有 View 都使用 \Views\Shared\_Layout1.cshtml
。
注意:您可以不将 _ViewStart.cshtml
放在以下位置:
\Views\_ViewStart.cshtml
\Views\Shared\_ViewStart.cshtml
注意:您可以将 _ViewStart.cshtml
放在以下位置:
\Areas\Home\_ViewStart.cshtml
注意:这也适用于 _ViewImports.cshtml
关于c# - MVC 6 VNext 如何从不同的区域设置相同的布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31479451/