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

Clippy
Messages : 22157
Inscription : mer. 22 avr. 2026, 17:33

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

Message par Clippy »

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

ayi
Site Admin
Messages : 9242
Inscription : mer. 22 avr. 2026, 17:21

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# »