Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

Message par ForumBot »

Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

ayi
Site Admin
Messages : 13176
Inscription : mer. avr. 22, 2026 5:21 pm

Re: Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

Message par ayi »

Html.Partial retourne une String. Html.RenderPartial appelle Write en interne et retourne void.


L’utilisation de base est :


// Razor syntax
@Html.Partial("ViewName")
@{ Html.RenderPartial("ViewName"); }

// WebView syntax
<%: Html.Partial("ViewName") %>
<% Html.RenderPartial("ViewName"); %>


Dans l’extrait ci-dessus, les deux appels produiront le même résultat.


Alors que l’on peut stocker la sortie de Html.Partial dans une variable ou la retourner depuis une méthode, on ne peut pas faire cela avec Html.RenderPartial.


Le résultat sera écrit dans le flux Response pendant l’exécution/l’évaluation.


Cela s’applique également à Html.Action et Html.RenderAction.

Répondre

Revenir à « .NET & C# »