Html.partial and Html.renderpartial

Source: Internet
Author: User

--excerpt from the ASP. NET MVC 4 Advanced Programming

The partial helper method is used to render a partial view into a string. The Partial method uses 4 overloaded versions, as follows:

 Public void Partial (string  partialviewname);  Public void Partial (stringobject  model);  Public void Partial (string  partialviewname, viewdatadictionary viewData);  Public void Partial (stringobject model, Viewdatadictionary viewData);

For example, the following code renders a partial view named Albumdisplay.

@Html. Partial ("albumdisplay")

The RenderPartial helper method is very similar to the Partial, but the renderpartial is not a return string but is written directly to the response output stream. For this reason, renderpartial must be placed in a code block, not in a code expression. For example, the following two lines of code write the same content to the output stream:

@Html. Partial ("albumdisplay") @{html.renderpartial ("  Albumdisplay");}

Which method should I use here? In general, because the partial is simpler, you should choose partial. However, RenderPartial has better performance because it is written directly to the response stream, but this advantage requires a lot of use (high site traffic or repeated calls in the loop) to see.

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.