1. First look at their peering relationship
@Html. Partial corresponds to @{html.renderpartial ();}
@Html. Action corresponds to @{html.renderaction ();}
The above statements correspond to each other, they realize the function is the same, the difference is the wording,
View of the 2.Action load method, execute the order of the Controller→model→view, and then return the resulting page back to the original view. Partial directly loads the contents of the view file
[email protected] can directly provide the user control name as a parameter, and html.action need to have a corresponding action, within the action return Partailresult (that is, Retun Partialview ()).
Such as: The following example can illustrate the use of @html.partial
Public ActionResult Index () { string[] Txtarry = {"1", "2", "3"}; viewdata["txt" = "welcome"; Return View (Txtarry); }
Index.cshtml page
<body> <div> @* here should show: 1*@ @Model [0] </div> <div> @* Call msg1.cshtml*@ @Html. Partial ("MSG1") </div></body>
If the @html.partial ("MSG1") does not pass a specific value, then it will default to the index in the model value passed, if there is a specific parameter, then the model value in the MSG1 is to pass over the parameter value
such as: @Html. Partial ("Msg1", (object) model[1])
Msg1.cshtml page
<body> <div> @Model [0][email protected]["TXT"] </div></body>
Summary: With @html.partial (page), then this page in the data source is "call page: Index.cshtml" To, as long as the index page can accept the ViewData so MSG1 can accept, The index page is the MSG1 page of the food and clothing parents. Finally, choose according to different uses.
@Html. Partial and @html.action differences