This article explains the differences between C# in more detail, and the specific analysis is as follows:
Both methods are used to embed user controls on the interface.
It is to directly embed the user control on the interface:
Render directly on the page View results The view must exist!
<%("LogOnUserControl");%>
or
<%("~/Areas/Comm/Views/Shared/");%>
Notice:When using the first method, the user control must be placed in the same directory as the caller, or in View/Shared.
Then call the user control through the Action in the Controller
The result of Action can be directly rendered on the page. The Controller can be specified. The returned can be all subtypes inherited from ActionResult.
Controller:----Controller where the user control is located
public ActionResult UserControl() { return PartialView(); }
View:---------View that calls the user control
<%("UserControl","Controller");%>
Personally, I prefer RenderPartial
RenderPartial and RenderAction are both methods used to display PartialView in Mvc, so when to use which method is the first problem I encountered. To make the right choice, you need to have a full understanding of these two and know the similarities and differences. This is also the subject of this article.
Similarities between the two:
RenderPartial and RenderAction are usually used to display a relatively independent "block", such as displaying menus or navigation bars. Both output results are displayed as part of the called View.
The differences between the two:
The data of RenderPatial comes from the call View, while the RenderAction comes from itself.
RenderAction will initiate a new Request, while RenderPatial will not.
How to choose:
According to the second point of the two, since RenderAction will call a new Action method, and Action in Mvc is the smallest cache unit, if the data of a certain "block" is relatively fixed and will not change due to different visitors, then this is the time to use RenderAction. As an aside, a new Request will be initiated for RenderAction, which feels a bit disruptive to the process of calling the page. When a View is displayed, it initiates a Request to obtain data to display it, which obviously destroys the principle of being a View.