What is difference between Html.Partial() and Html.RenderPartial() in Asp.net Mvc?
In Asp.Net MVC, I have a Header partial view. I want to import it to my master page, I used Html.Partial()
to import it.
But in Html helper of Asp.net MVC provided another method to help import a partial view is Html.RenderPartial()
so what is the difference between them? and what is better?
Html.Partial()
and Html.RenderPartial()
-
M1
Marry Christ Dec 14 2020
Syntax:
// Razor syntax ASP.NET MVC @Html.Partial("ViewName") @{ Html.RenderPartial("ViewName"); } // Razor syntax ASP.NET Core @await Html.PartialAsync("ViewName") @{ Html.RenderPartialAsync("ViewName"); }
Differences:
Html.Partial()
returns a String.Html.RenderPartial()
returns void, it writes directly to the response of the application.About performance because
RenderPartial()
writes directly to the response stream so it's better. -
M0
Manish Kumar Dec 14 2020
Html.Partial()
:Returns Html string.
Injects the Html string of the partial view into the main view.
Performance is slow.
No need to be inside the braces.
Html.RenderPartial()
:Returns void.
Writes Html in the response stream.
Perform is faster compared with
HtmlPartial()
.Must be inside braces @{ }.
* Type maximum 2000 characters.
* All comments have to wait approved before display.
* Please polite comment and respect questions and answers of others.