Partial and RenderPartial:
These two properties are the same, only refers to a set in a View to come in, but the return value is a little different from
a return of Object Partial (MvcHtmlString), return a String to a pile of Html return out, then written to main page
@Html.Partial("ViewName")
RenderPartial return is void, and this method adds the specified View the main page
@{
Html.RenderPartial("ViewName");
}
These two methods did not use Controller, directly to a View (Page) to add to the mix
and RenderAction a bit different, this is a Action, it will be used later to return to pass a page Controller
public class ChildActionOnlyTestController : Controller
{
[ChildActionOnly]
public ActionResult GetSupplierList()
{
var controller = new SupplierController();
return controller.SupplierList();
}
}
RenderPartial RenderAction and the same two points
It is commonly used to display a relatively independent function of "block", for example, to display the menu, or a navigation bar. The results are displayed on both of output of the call as part of View.
The differences between the two
- RenderPatial data from the View calls, and RenderAction from himself.
- RenderAction will launch a new Request, and RenderPatial not.
PartialView:<div>Just a PartialView [email protected]</div> @ViewBag.Test
View:<p> @{Html.RenderPartial("ViewUserControl1");} @Html.Partial("ViewUserControl1") @{Html.RenderAction("ViewUserControl1");} @Html.Action("ViewUserControl1") </p>
Controller:Controller: [ChildActionOnly] // prevent direct call public ActionResult ViewUserControl1() { ViewBag.Test = "(Action) calls"; return PartialView(); }
http://www.cnblogs.com/gesenkof99/archive/2013/06/03/3115052.html