由于 Razor 脚本标记,完整身份脚手架失败

问题描述

我为所有 Razor 视图搭建了脚手架,因为我想编辑它们。

然而,其中一些在底部有这个:

@section Scripts {
<partial name="_ValidationScriptsPartial" />
}

这是我得到的错误:

InvalidOperationException:以下部分已定义但尚未由位于“/Areas/Identity/Pages/Account/Manage/_Layout.cshtml”的页面呈现:“脚本”。要忽略未渲染的部分,请调用 IgnoreSection("sectionName").

请注意,我确实希望呈现这些脚本。为什么会崩溃?如何最好地解决它?

解决方法

参考此thread

这意味着您已经在主 Layout.cshtml 中定义了一个部分,但您没有在视图中包含该部分的任何内容。

在您的 /Areas/Identity/Pages/Account/Manage/_Layout.cshtml 中,它应该包含代码:

@section Scripts 
{
    @RenderSection("Scripts",required: false)
}

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...