ASP. net mvc 3 has been officially released for some time. Now it is estimated that many people are studying hard, and I can't exception it. I just saw an articleArticleThis section describes three very useful methods: renderbody, 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, you will see the following statement in the tag:
@ Renderbody ()
In fact, this function is similar to the server control in the master page. When you create a view based on this layout page, the view content is merged with the layout page, the content of the newly created view is displayed between 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 ()
CodeIt is concise and intuitive. In addition, it seems that the underlined View File has special meanings. 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 { Footer here }
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