Car*_*ire 4 c# asp.net-mvc razor
如何在MVC 6 Vnext中从不同区域设置相同的布局,
我在每个区域使用_ViewImports.cshmlt和_ViewStart.cshtml
在_ViewStart.cshtml中
@{
Layout = "_/Views/Shared/_Layout.cshtml";
}
Run Code Online (Sandbox Code Playgroud)
和_ViewImports.cshtml
@using Cross2Enterprise.Administrador
@using Cross2Enterprise.Administrador.Models
@using Microsoft.Framework.OptionsModel
@addTagHelper "*, Microsoft.AspNet.Mvc.TagHelpers"
Run Code Online (Sandbox Code Playgroud)
我认为这是你的情景:
\Areas文件夹为此,请使用以下项目布局:
\Areas\Home
\Areas\Home\Controllers
\Areas\Home\Views
\Areas\_ViewStart.cshtml
\Views
\Views\Shared\
\Views\Shared\_Layout1.cshtml
\Views\Shared\_Layout2.cshtml
Run Code Online (Sandbox Code Playgroud)
然后在文件中,\Areas\_ViewStart.cshtml您可以拥有以下内容:
@{
Layout = "_Layout1";
}
Run Code Online (Sandbox Code Playgroud)
这将使所有区域的所有视图都使用\Views\Shared\_Layout1.cshtml.
注意:您不能放入_ViewStart.cshtml以下位置:
\Views\_ViewStart.cshtml
\Views\Shared\_ViewStart.cshtml
Run Code Online (Sandbox Code Playgroud)
注意:您CAN把_ViewStart.cshtml在以下位置:
\Areas\Home\_ViewStart.cshtml
Run Code Online (Sandbox Code Playgroud)
注意:这也适用于_ViewImports.cshtml
我只是贬低了明显的事情......你试过......?(我只看了一些关于VNext的事情)
Layout = "~/Views/Shared/_Layout.cshtml";
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2228 次 |
| 最近记录: |