ASP. net MVC 3 has been officially released. Now it is estimated that many people are studying hard, and I am not an exception. I just saw an article and introduced three very useful methods: renderbody, now let's summarize the renderpage and rendersection.
1. renderbody
Without the "Master page" in the razor engine, the "layout" Page (_ layout. cshtml) is placed in the shared view folder. On this page, the <body> tag contains the following statement:
@ Renderbody ()
In fact, its role is similar to the <contentplaceholder> Server Control on the master page. When you create a view based on the layout page, the view content is merged with the layout page, the content of the newly created view is displayed between the <body> labels through the @ renderbody () method of the layout page.
This method does not require parameters and can only appear once.
2. renderpage
We can guess from the name that this method is to render 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 ()
The code is concise and intuitive. In addition, it seems that the underlined View File has special meanings. Please study it later.
3. rendersection
The layout page also has the concept of section. That is to say, if a section is defined in a view template, it can be presented separately. The usage is as follows:
@ Renderpage ("~ /Views/shared/_ header. cshtml ")
@ Renderbody ()
@ Rendersection ("footer ")
Of course, you must define the section in the view. Otherwise, an exception occurs:
@ Section footer {
<B> footer here </B>
}
To prevent exceptions due to missing sections, You can provide rendersection () with 2nd parameters:
@ Rendersection ("footer", false)
Http://www.dotnetcurry.com/ShowArticle.aspx? Id = 636