Html.partial and html.renderpartial in MVC

Source: Internet
Author: User

The partial helper method is used to render a partial view into a string. Note It is not necessary to specify the path and file name extension for the view because the run-time location portion of the view is the same logic used to locate the normal view . For example, the following code renders a partial view named Albumdisplay. The runtime uses all available view engines to find:

@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. To illustrate this, the following two lines of code write the same content to the output stream:

@{html.renderpartial ("Albumdisplay");}

@Html. Partial ("Albumdisplay")

So, which method should I use? In general, because partial is more convenient than renderpartial , you should select partial. However,RenderPartial has better performance because it is written directly to the response stream, but this performance advantage requires a lot of use (high site traffic or repeated calls in the loop) to see it.

--Excerpt from "ASP. MVC4 Advanced Programming" (fourth edition)

Html.partial and html.renderpartial in MVC

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.