简体   繁体   中英

What is the difference between RenderSection and Web Helper

What is the difference between RenderSection , RenderPage and a Web Helper?

  • List item I've used 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.
  • I've used RenderSection , which I believe only takes 1 parameter; the name of the section .
  • I've also used Web Helpers. This is where I get confused. With Helpers, you can pretty much so everything you can do with 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM