I try to use the @RenderSection in my website which built with Razor script. I got error when use it with the .cshtml files. It also didn't appear in the IntelliSense at VS.
Now, I just realized that if I remove the @page from the .cshtml file then the error gone and also the IntelliSense offer me the @RenderSection
And my question is: why?
It says in the Microsoft documentation / tutorial that with the new ASP.NET Core Razor scripts:
"@page must be the first Razor directive on a page. @page affects the behavior of other Razor constructs."
So I'm a little bit confused. What's the right way to include html (partial views - like main menu, etc.) in a .cshtml file with the new Razor Pages in ASP.NET Core ?
Thanks.
I have work around on this and found when you use
@RenderSection
in child page than it should be inside any section of its parent page(i.e. _layout.cshtml)Here your
_layout.cshtml
should be like,Your child page should like,
And your nested child page should like,