gpt4 book ai didi

c# - 区域共享布局_ViewStart.cthml

转载 作者:行者123 更新时间:2023-11-30 22:53:57 26 4
gpt4 key购买 nike

我有多个区域,我想将我的布局指向我的共享区域文件夹。我的文件夹是

App
-...
-Model
-...
-Controller
-...
-View
|-Shared
- _layout.cshtml <--- root layout
- _layout2.cshtml <--- workaround
- _ViewStart.cshtml <--- OK!
-Areas
|-Areaname1
|-Controllers
|-Views
|-Shared
- _layout.cshtml <--- my area layout
- _ViewStart.cshtml <--- i want to use the layout above
|-Areaname2
-...

我的 Areas Views/ _ViewStart.chtml

代码
@{
// Layout = "~/Views/Shared/_Layout.cshtml"; <--- will point on the root layout
// Layout = "~/Views/Shared/_Layout2.cshtml"; <--- view to root
// Layout = "~Area/Areaname1/Views/Shared/_Layout.cshtml"; <--- correct path
// Layout = "~/Areaname1/Views/Shared/_Layout.cshtml"; <--- same error above
}

将布局指向一个区域。

最佳答案

通过使用

@{
Layout = "~/Views/Shared/_Layout.cshtml"; <--- will point on the root layout
}

你明确地说,查看根 (~) 并使用 /Views/Shared/_Layout.cshtml

你可能想使用:

@{
Layout = "_layout.cshtml";
}

这首先会在您的区域文件夹中查找,如果在那里没有找到任何 _layout.cshtml,它将在 ~/Views/Shared/ 文件夹中查找。

您可以在 RazorViewEngine 中设置查找路径或向其注册一些自定义项。 See the source code例如。

默认情况下它们是:

  • "~/Areas/{2}/Views/{1}/{0}.cshtml",
  • "~/Areas/{2}/Views/{1}/{0}.vbhtml",
  • "~/Areas/{2}/Views/Shared/{0}.cshtml",
  • “~/Areas/{2}/Views/Shared/{0}.vbhtml”
  • "~/Views/{1}/{0}.cshtml",
  • "~/Views/{1}/{0}.vbhtml",
  • "~/Views/Shared/{0}.cshtml",
  • “~/Views/Shared/{0}.vbhtml”

地点:

  • 2 = 面积
  • 1 = Controller
  • 0 = Action / View (例如_layout)

关于c# - 区域共享布局_ViewStart.cthml,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56679158/

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