Both of them can output a Partial view. The difference is as follows:
1. Partial has a return value (MvcHtmlString); RenderPartial has no return value (Void ).
Definition
1 // PartialExtensions. Partial method (HtmlHelper, String)
2 public static MvcHtmlString Partial (
3 this HtmlHelper htmlHelper,
4 string partialViewName
5)
6
7 // RenderPartialExtensions. RenderPartial method (HtmlHelper, String)
8 public static void RenderPartial (
9 this HtmlHelper htmlHelper,
10 string partialViewName
11)
2. Partial output to the Temporary Variable StringWriter; RenderPartial output to HtmlHelper. ViewContext. Writer (that is, directly output to Response ).
Internal Implementation of Html. Partial
Public static MvcHtmlString Partial (this HtmlHelper htmlHelper, string partialViewName)
{
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 ());
}
}
Internal Implementation of Html. RenderPartial
1 public static void RenderPartial (this HtmlHelper htmlHelper, string partialViewName)
2 {
3 htmlHelper. RenderPartialInternal (partialViewName, htmlHelper. ViewData, null, htmlHelper. ViewContext. Writer, ViewEngines. Engines );
4}
3. the syntax in the Razor view is different:
Syntax
1 @ Html. Partial ("PartialViewName ")
2
3 @ {Html. RenderPartial ("PartialViewName ");}
Logistics, goods distribution, freight transportation, websites, forums, exchanges, information publishing
QQ website construction: 471226865