Razor: @Html.Partial() vs @RenderPage()

后端 未结 5 781
误落风尘
误落风尘 2020-11-30 20:02

What is the appropriate way of rendering a child template?

And what\'s the difference? Both seem to work for me.

And why does @Html.RenderPartial()

5条回答
  •  青春惊慌失措
    2020-11-30 20:35

    The RenderPartial method doesn’t return HTML markup like most other helper methods. Instead, it writes content directly to the response stream, which is why we must call it like a complete line of C#, using a semicolon.

    This is slightly more efficient than buffering the rendered HTML from the partial view, since it will be written to the response stream anyway. If you prefer a more consistent syntax, you can use the Html.Partial method, which does exactly the same as the RenderPartial method, but returns an HTML fragment and can be used as @Html.Partial("Product", p).

提交回复
热议问题