Html.RenderPartial與Html.RenderAction這兩個方法都是用來在界面上嵌入用戶控件的。web
Html.RenderPartial是直接將用戶控件嵌入到界面上:spa
<%Html.RenderPartial("LogOnUserControl");%>orm
或ci
<%Html.RenderPartial("~/Areas/Comm/Views/Shared/LogOnUserControl.ascx");%>it
注意:用第一種方法時,用戶控件必須放在調用者同一目錄下,也能夠放在View/Shared中。io
Html.RenderAction則經過Controller中的Action來調用用戶控件form
Controller:----用戶控件所在Controllerclass
public ActionResult UserControl() { return PartialView(); }transform
View:----調用用戶控件的Viewwebkit
<%Html.RenderAction("UserControl","Controller");%>