Differences between Html. RenderPartial and Html. RenderAction and Html. Partial in asp.net mvc

Source: Internet
Author: User
Differences between Html. RenderPartial and Html. RenderAction

Both Html. RenderPartial and Html. RenderActionp are used to embed the MVC user control into the View.

Html. RenderPartial is to directly embed the MVC user control into the interface.

Rendering in the full view

Html. renderPartial (string partialName); Html. renderpartial (string partialName, object model); Html. renderPartial (string partialName, ViewDataDictionary viewData); Html. renderPartial (string partialName, object model, ViewDataDictionary viewData); The RenderPartial function loads local attempts directly and transmits the data to a local attempt without a Controller.

<% Html. RenderPartial ("SupplierList"); %> note: the MVC user control must be placed in the same directory of the caller or in View/Shared.

<% Html. RenderPartial ("~ /Views/Supplier/SupplierList. ascx "); %> specifies the directory of the MVC user control.

Html. RenderAction calls the MVC user control through the Action in the Controller.

Added Html in MVC 2.0. renderAction (); this method RenderPartial is a bit different. He directly re-executes the order of Controller → Model → View, and then returns the generated page to the original View.

Therefore, the parameters passed in Html. RenderAction are the name of the Controller and Action to be executed. If a method in the controller can only be called by Html. RenderAction (), you can add the feature [ChildActionOnly] to the method. The feature cannot be accessed elsewhere.

PublicclassChildActionOnlyTestController: Controller

{

[ChildActionOnly]

PublicActionResultGetSupplierList ()

{

Varcontroller = newSupplierController ();

Returncontroller. SupplierList ();

}

}

The following figure shows the execution process comparison.

Post this comment to Weibo

Extension methods of the three HtmlHelper

Html. Partial: directly generates a string for the View content and returns it,

The Html. RenderPartial method is directly output to the current HttpContext,

The Html. RenderAction also calls the Action. Repeat the sequence of Controller → Model → View.

Therefore, they are used differently in the view.

:

Related Article

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.