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

纵饮孤独 提交于 2019-11-26 23:29:27

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.

HTML.RenderPartial is not returning HTML markup like most other helper methods. In place of, the method writes content directly to the response stream, which is why developer must call it like a entire line of C#, using a semicolon. This is slightly more effectual than buffering the rendered HTML from the partial view, since it will be written to the response stream anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!