Wednesday 25 July 2012

Html.Partial vs Html.RenderPartial

Html.Partial returns a string, Html.RenderPartial calls Write internally, and returns void. The usage (using Razor syntax):

@Html.Partial("ViewName")

@{ Html.RenderPartial("ViewName");  }
The usage (using WebForms syntax):

<%: Html.Partial("ViewName") %>

<% Html.RenderPartial("ViewName"); %>
Will do exactly the same. You can store the output of Html.Partial in a variable, or return it from a function. You cannot do this with Html.RenderPartial. The result will be written to the Response stream during the execution. The same is true for Html.Action and Html.RenderAction.

No comments:

Post a Comment