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.
: