gpt4 book ai didi

c# - MVC 6 VNext 如何从不同的区域设置相同的布局

转载 作者:太空狗 更新时间:2023-10-30 00:14:12 25 4
gpt4 key购买 nike

如何在 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"

最佳答案

我认为这是你的场景:

  1. 带有 MVC 的 ASP.NET Core
  2. 使用 \Areas 文件夹
  3. 您想在一个位置设置所有区域使用的模板

为此,有以下项目布局:

\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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com