我有三个简单的布局,
_Layout.cshtml(这是基本布局)
@RenderSection("something",required: false) @RenderBody()
_Main.cshtml
@{ Layout = "~/Views/Shared/_Layout.cshtml"; } @section something { Hey I'm actually on the _Main layout. }
Index.cshtml
@{ Layout = "~/Views/Shared/_Main.cshtml"; }
当我尝试在一个动作中渲染索引视图时,我得到这个错误,
The “RenderBody” method has not been called for layout page
“~/Views/Shared/_Main.cshtml”.
但是等等,_Main.cshtml有一个已经有一个RenderBody()的父版本。
所以我错了,我必须为每个孩子布局调用RenderBody()?