布局有这个:
<!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/