<body> @RenderBody() </body>
Without the "Master page" in the Razor engine, the "Layout" Page (_ Layout. cshtml) is placed in the shared view folder. On this page, you will see a statement in the <body> tag: @ RenderBody ()
ActuallyIts role is similar to the <contentplaceholder> Server Control on the master page.When you create a view based on this layout page, the content of the view is merged with the layout page, and the content of the newly created view is directed to the @ RenderBody () of the layout page () the method floated between <body> labels.
This method does not require parameters and can only be presented once.
<body> @RenderPage("~/Views/Shared/_Header.cshtml")
@RenderBody() </body>
You can guess from the name.This method is to create a page. For example, a Fixed Header in a webpage can be separately placed in a shared view file, and then called through this method in the layout page. The usage is as follows:
@ RenderPage ("~ /Views/Shared/_ Header. cshtml ")
@ RenderBody ()
<body> @RenderPage("~/Views/Shared/_Header.cshtml")
@RenderBody()
@RenderSection("footer") </body>
The layout page also has the concept of Section,Used to display a section defined in the view template individuallyThe usage is as follows:
@ RenderPage ("~ /Views/Shared/_ Header. cshtml ")
@ RenderBody ()
@ RenderSection ("footer ")
Define the section in the view. Otherwise, an exception occurs.
@section footer {
<b>Footer Here</b>
}
To prevent exceptions due to lack of sections, You can provide 2nd parameters to RenderSection:
@ RenderSection ("footer", false)