两者都可以输出一个Partial视图;其区别如下:
1. Partial有返回值(MvcHtmlString);RenderPartial没有返回值(Void)。
![[转]Html.RenderPartial和Html.Partial在Razor视图中的区别](https://i-blog.csdnimg.cn/blog_migrate/4cff16d3715b308140b352770d969fdc.png)
2 public static MvcHtmlString Partial(
3 this HtmlHelper htmlHelper,
4 string partialViewName
5 )
6
7 // RenderPartialExtensions.RenderPartial 方法 (HtmlHelper, String)
8 public static void RenderPartial(
9 this HtmlHelper htmlHelper,
10 string partialViewName
11 )
2. Partial输出到临时变量StringWriter ;RenderPartial输出到HtmlHelper.ViewContext.Writer上(即直接输出到Response)。
![[转]Html.RenderPartial和Html.Partial在Razor视图中的区别](https://i-blog.csdnimg.cn/blog_migrate/4cff16d3715b308140b352770d969fdc.png)
{
return htmlHelper.Partial(partialViewName, null, htmlHelper.ViewData);
}
public static MvcHtmlString Partial( this HtmlHelper htmlHelper, string partialViewName, object model, ViewDataDictionary viewData)
{
using (StringWriter writer = new StringWriter(CultureInfo.CurrentCulture))
{
htmlHelper.RenderPartialInternal(partialViewName, viewData, model, writer, ViewEngines.Engines);
return MvcHtmlString.Create(writer.ToString());
}
}
![[转]Html.RenderPartial和Html.Partial在Razor视图中的区别](https://i-blog.csdnimg.cn/blog_migrate/4cff16d3715b308140b352770d969fdc.png)
2 {
3 htmlHelper.RenderPartialInternal(partialViewName, htmlHelper.ViewData, null, htmlHelper.ViewContext.Writer, ViewEngines.Engines);
4 }
3. 在Razor视图中语法不一样:
![[转]Html.RenderPartial和Html.Partial在Razor视图中的区别](https://i-blog.csdnimg.cn/blog_migrate/4cff16d3715b308140b352770d969fdc.png)
2
3 @{ Html.RenderPartial( " PartialViewName "); }
在最近的工作中,用到@{Html.RenderPartial("_RoomBottom");}个别页面虽然断点已经进到里面,却无法输出,
改成@Html.Partial("_RoomBottom")之后输出正常。