ASP.Net MVC 以下部分已定义但尚未为布局页面呈现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13336117/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 16:42:00  来源:igfitidea点击:

ASP.Net MVC The following sections have been defined but have not been rendered for the layout page

.netasp.net-mvc

提问by Slippy

I have seen in a google search that some other people have had this problem... but their issue doesn't involve getting rid of default begaviour.

我在谷歌搜索中看到其他一些人也遇到过这个问题……但他们的问题并不涉及摆脱默认行为。

ok... I am useing ASP.Net MVC4. I can't stand it, but you know how it is these days, we all end up working with technology we can't stand from time to time.

好的...我正在使用 ASP.Net MVC4。我无法忍受,但你知道现在是怎么回事,我们最终都会不时地使用我们无法忍受的技术。

in my _layout.cshtml file, I have got rid of the following lines.

在我的 _layout.cshtml 文件中,我删除了以下几行。

    @RenderSection("featured",false)
    @RenderBody()
    @Scripts.Render("~/bundles/jquery")
    @RenderSection("scripts",false)

When I run my application, I get the following error :

当我运行我的应用程序时,我收到以下错误:

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

以下部分已定义但尚未为布局页面“~/Views/Shared/_Layout1.cshtml”呈现:“featured”

If I put the lines back in, I get the junk from the standard ASP.NET HelloWorld template... Do I need to remove or modify something else?

如果我把这些行放回去,我会从标准的 ASP.NET HelloWorld 模板中得到垃圾……我需要删除或修改其他东西吗?

回答by Grimace of Despair

I guess your view contains "@section featured", which means it tries to output something which it identifies as "featured". Where the output actually ends up, you can specify by RenderSection in your Layout.

我猜您的视图包含“@section features”,这意味着它会尝试输出它标识为“featured”的内容。输出实际结束的位置,您可以在布局中通过 RenderSection 指定。

So if you don't do a RenderSection, ASP.NET doesn't know where to put the contents that view tries to output. Hence the error.

因此,如果您不执行 RenderSection,ASP.NET 不知道将视图尝试输出的内容放在哪里。因此错误。

So your solution is probably to also get rid of the "@section featured" block.

所以你的解决方案可能也是摆脱“@section features”块。