简体   繁体   English

似乎需要可选部分

[英]Optional sections appear to be required

I have a Layout page which has the following 我有一个布局页面,其中包含以下内容

@RenderSection("Style", required: false)
@RenderSection("Scripts", required: false)
@RenderBody()

My project was working just fine until a few days ago, now all the new views I create I get the following error 直到几天前,我的项目都运行良好,现在我创建的所有新视图都收到以下错误

The following sections have been defined but have not been rendered for the layout page "~/Views/Shared/_Layout.cshtml": "Style; Scripts". 已经定义了以下部分,但尚未为布局页面“〜/ Views / Shared / _Layout.cshtml”呈现:“样式;脚本”。

I Get the same error for RenderBody if I remove Style and Script. 如果删除“样式”和“脚本”,我将得到与RenderBody相同的错误。 As I said, my old pages work just fine, the new pages I create have this error, I even replaced the whole code of an old page in a new page and still got the same error. 如我所说,我的旧页面工作正常,我创建的新页面出现此错误,我什至在新页面中替换了旧页面的整个代码,但仍然遇到相同的错误。

Figured it out, 弄清楚了,

I have a code at the top of the page in @{} which checked for permission, somehow that was causing this issue. 我在@ {}页面顶部的代码中检查了权限,以某种方式导致了此问题。

It's working find now, until next time :D 现在可以正常工作,直到下次:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM