What is the difference (if any) between Html.Partial(view, model) and Html.RenderPartial(view,model) in MVC2?

前端 未结 2 2117
执念已碎
执念已碎 2020-11-28 19:15

Other than the type it returns and the fact that you call it differently of course

<% Html.RenderPartial(...); %>
<%= Html.Partial(...) %>  
         


        
2条回答
  •  不知归路
    2020-11-28 19:50

    The only difference is that Partial returns an MvcHtmlString, and must be called inside <%= %>, whereas RenderPartial returnsvoid and renders directly to the view.

    If you look at the source code, you'll see that they both call the same internal method, passing a StringWriter for it to render to.

    You would call Partial if you want to view, save, or manipulate the generated HTML instead of writing it to the page.

提交回复
热议问题