c# - RenderSection() 在 ASP.NET Core 的 <environment> 标签助手中工作吗?

标签 c# asp.net razor asp.net-core tag-helpers

布局有这个:

<!DOCTYPE html>
<html>
<head>
  <environment names="Development">@RenderSection("devCss", required: false)</environment>
  <environment names="Staging,Production">@RenderSection("staproCss", required: false)</environment>
</head>
<body>
  @RenderBody()
  <environment names="Development">@RenderSection("devJs", required: false)</environment>
  <environment names="Staging,Production">@RenderSection("staproJs", required: false)</environment>
</body>
</html>

View 有这个:
@section devCss { <link rel="stylesheet" href="foo.css" asp-append-version="true" /> }
@section staproCss { <link rel="stylesheet" href="foo.min.css" asp-append-version="true" /> }
@section devJs {}
@section staproJs {}

<h1>hello</h1>

RenderSection()<environment>外面标签,一切正常。

在内部时,如上例所示,它失败并显示无用的错误 InvalidOperationException: The following sections have been defined but have not been rendered by the page at '_Layout.cshtml': 'staproCss, staproJs'. To ignore an unrendered section call IgnoreSection("sectionName").
这显然没有意义,因为所有部分都已定义。它提示一些人,而不是其他人。

是否<environment>标签助手允许 RenderSection()在里面?

最佳答案

只需添加 @RenderSection("Scripts", required: false)</body>标签。

关于c# - RenderSection() 在 ASP.NET Core 的 <environment> 标签助手中工作吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40289783/

相关文章:

c# - 如何解析 XML 字符串 c#

c# - 我应该如何在 WPF 窗口中动态创建用户控件?

c# - 我将如何使用 c#/asp.net 去 abouce decodeURI

asp.net - DBContext.Entry 的作用是什么?

asp.net - 发布时出现 Dot Net Core 构建错误 - 目标标签名称不能为空或空格

.net - .CSHTML 中的 Visual Studio 2010 代码格式 - 不正确的缩进

c# - 如何存储 BIG int 值

c# - ListView 中奇怪的寻呼机行为

php - 如何为视频添加动态链接?

c# - 是否可以从组件继承 Razor 标记?