How to use: @Html. Action (action, Controller)
Loads a partial page.
For example, use in a template page: @Html. Action ("Contact", "Company")
In Companycontroller, there are the following methods:
Public Partialviewresult Contact ()
{
return Partialview ();
}
@html.partial,@html.action,@html.renderpartial,@html.renderaction differences in ASP. NET MVC
make a summary of these four differences, clean up your ideas and facilitate future applications:
1, with the method of the render return value is void, the output within the method; The return value type is mvchtmlstring, so it can only be applied as follows:
@html.partial corresponds to @{html.renderpartial (...). );}
@html.action corresponds to @{html.renderaction (...). );}
2, Action, renderaction loading method of the view, to fulfill the order of Controller→model→view, and then the resulting page back to the original view and then return. Partial and renderpartial directly load the contents of the view file
3. Html.partial can directly supply the user control name as a parameter, and html.action needs a corresponding action to return Partailresult (that is, Retun Partialview ()) within the action.
4, for simple user control without any logic, recommended application html.partial; For user controls that need to have some model set, it is recommended to apply html.action. Of course, there are model data can also be applied html.partial method, you can see the method of overloading.
5, the application of html.action has a benefit, that is, you can select the appropriate user control according to the scene. 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. Action ()