MVC partial view: Partial (), renderpartial (), Action (), Renderaction (), renderpage () differences

Source: Internet
Author: User

There are several ways to load a partial view in a view, including:

The Partial () Action () renderpartial () renderaction () Renderpage () method.

The following are the differences between these methods:

Partial and RenderPartial methods

1. Razor syntax: @Html. Partial () and @{html.renderpartial ();}

2. Difference: Partial can directly output the content, it is inside the HTML content is converted to string character (mvchtmlstring), and then cached, and finally output to the page at once. Obviously, this conversion process will reduce the efficiency, so usually use renderpartial instead.

RenderPartial and Renderaction method

1. Razor syntax: @{html.renderpartial ();} With @{html.renderaction ();}

2. Difference: RenderPartial does not need to create the Controller's action, and renderaction needs to create the action to load in the controller.

Renderaction will call Contorller's Action first and then render the view, so the page will start a link.

If this part of the view is just some simple HTML code, please use RenderPartial. But if this part of the view needs to be rendered by reading the data in the database, in addition to the HTML code, it is necessary to use renderaction because it can call the model method in the Action to read the database, render the view and render it, and Renderp Artial has no Action, so it can't be done.

Partial views of renderaction rendering are equivalent to completely independent page content and the original page is completely independent (such as model ViewBag)

Some views of the renderpartial rendering can use the Model and ViewData of the original view.


Renderaction and Action

1. Razor syntax: @{html.renderaction ();} With @Html. Action ();

2. Difference: Action is also a direct output, and the same as Partial, there is a conversion process. Renderaction output directly to the current HttpContext efficiency.


Renderpage and RenderPartial method

1. Razor syntax: @{html.renderpartial ();} With @RenderPage ()

MVC partial view: Partial (), renderpartial (), Action (), Renderaction (), renderpage () differences

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.