not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".

“/MvcMusicStoreV3”应用程序中的服务器错误。

使用模板创建的Controller,

not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".

运行Edit和Create会出现下面错误提示,而其它页面则不会。

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Scripts".

说明: 执行当前 Web 请求期间,出现未经处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。
异常详细信息: System.Web.HttpException: The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Scripts".
源错误:

原因分析:

由参考文献知,由于开发环境默认给Edit和Create文件中添加了:

@section Scripts {
    @Scripts.Render("~/bundles/jqueryval")
}

not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".

not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".

而在Share/_Layout.cshtml中没有进行声明引发的。

解决方案是在Share/_Layout.cshtml添加一个声明就可。

@RenderSection("scripts", required: false)

not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".

运行效果:

not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".

参考文献:

http://stackoverflow.com/questions/10971149/the-following-sections-have-been-defined-but-have-not-been-rendered-for-the-layo

not been rendered"~/Views/Shared/_Layout.cshtml": "Scripts".