In ASP. @html.partial, @Html. Action, @Html. renderpartial, @Html. Renderaction differences
Make a summary of these four differences, clean up the idea, convenient for later use:
1. The return value of the method with render is void, output inside the method, and the return value type is mvchtmlstring, so this can only be used:
@Html. Partial corresponds to @{html.renderpartial (...);}
@Html. Action corresponds to @{html.renderaction (...);}
2, Action, renderaction loading method of the view, the execution of Controller→model→view order, and then the resulting page back to the original view and then callback. Partial and renderpartial directly load the contents of the view file
3. Html.partial can provide the user control name directly as a parameter, and html.action needs a corresponding action to return Partailresult (that is, Retun Partialview ()) within the action.
4, for a simple user control without any logic, it is recommended to use html.partial; for user controls that need to set some model, Html.action is recommended. Of course, there are model data can also use the Html.partial method, you can see the overloads of the method.
5, the use of html.action has the advantage that can be based on different scenarios to choose a different user control. Like what:
@Html. Action ("Userinfocontrol")
In the corresponding Userinfocontrol this action, when the user is not logged in, you can Retun Partialview ("Logonusercontrol"), after logging in, you can Retun Partialview (" Userinfocontrol ");
@Html. Partial, @Html. Action, @Html. renderpartial, @Html. Renderaction differences