公告
财富商城
积分规则
提问
发文
2018-12-31 05:46发布
只靠听说
In ASP.NET MVC, what is the difference between:
Html.Partial
Html.RenderPartial
Html.Action
Html.RenderAction
The return type of Html.RenderAction is void that means it directly renders the responses in View where the return type of Html.Action is MvcHtmlString You can catch its render view in controller and modify it by using following method
void
MvcHtmlString
protected string RenderPartialViewToString(string viewName, object model) { if (string.IsNullOrEmpty(viewName)) viewName = ControllerContext.RouteData.GetRequiredString("action"); ViewData.Model = model; using (StringWriter sw = new StringWriter()) { ViewEngineResult viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName); ViewContext viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, sw); viewResult.View.Render(viewContext, sw); return sw.GetStringBuilder().ToString(); } }
This will return the Html string of the View.
This is also applicable to Html.Partial and Html.RenderPartial
最多设置5个标签!
The return type of
Html.RenderAction
isvoid
that means it directly renders the responses in View where the return type ofHtml.Action
isMvcHtmlString
You can catch its render view in controller and modify it by using following methodThis will return the Html string of the View.
This is also applicable to
Html.Partial
andHtml.RenderPartial