What is the difference between RenderSection
, RenderPage
and a Web Helper?
RenderPage
, and it takes 2 parameters; the name of the file on disk, and an array of object
s to be passed to that page. RenderSection
, which I believe only takes 1 parameter; the name of the section
. RenderBody
, and RenderSection
. Here's where I get confused:
Sections file:
@section footer {
<p>Copyright 2012 blah. Most rights reserved.</p>
}
Helper file:
@helper header {
<p>Copyright 2012 blah. Most rights reserved.</p>
}
CSHTML File:
...
<body>
@MyHelpers.header()
@RenderBody()
@RenderSection("footer", required: true)
</body>
...
RenderSection()
and RenderBody()
allow you to communicate between the layout page and the content page.
You call these methods in the layout page, and they return content from the content page.
By contrast, helpers can only be called in the file they're defined in. (or, for global helpers, from anywhere)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.