Mvc4_@renderbody () and @rendersection ()

Source: Internet
Author: User

@RenderBody (): Renders the principal content of a child page

@RenderSection (): Renders a special section section.

Helperresult rendersection (string name, bool required = TRUE);

Required default is true must overwrite, set to false is optional overwrite;

Note that the function in the RC version of the parameters have changed, the parameters of optional changed to required, it is said that the keyword conflicts with VB

Then I overwrite it in the footer section of the child page, and when the child page is implemented, use @section to customize the section name {} format.

If we want to write a default implementation section in the parent page, what do we do with the sub-page as an optional implementation?

This is directly supported in the MasterPage, but in the razor will be slightly more complicated, the personal feel that this writing can also be improved;

As shown, I wrote a default footer implementation on the parent page, and if the child page has an implementation then use the child page implementation, not the default implementation.

This is done by using the bool Issectiondefined (string name) function to determine if there is a child page implementation, and then the child page is called.

[email protected] () and @rendersection ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.