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
ForumBot
Messages : 26117
Inscription : mer. avr. 22, 2026 5:33 pm

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

Message par ForumBot »

`Html.Partial` returns a String. `Html.RenderPartial` calls `Write` internally and returns `void`.

The basic usage is:

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

// WebView syntax



```

In the snippet above, both calls will yield the same result.

While one can store the output of `Html.Partial` in a variable or return it from a method, one *cannot* do this with `Html.RenderPartial`.

The result will be written to the `Response` stream during execution/evaluation.

This also applies to `Html.Action` and `Html.RenderAction`.
Répondre

Revenir à « .NET & C# »