Html.Partial或Html.RenderPartial与MVC3? [英] Html.Partial or Html.RenderPartial with MVC3?

查看:115
本文介绍了Html.Partial或Html.RenderPartial与MVC3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我甚至看到了下面的解释后,我完全糊涂了。

I am totally confused even after seeing the following explanation.

<div>
  @Html.Partial("_FeaturedProduct")
</div>

部分视图可以在里面布局页面渲染(或者如果使用MVC 2/3瓦特/ ASPX,母版页​​),以及定期的意见。

Partial views can be rendered inside a Layout Page (or if using MVC 2/3 w/ASPX, the Master Page) as well as regular views.

有一些情况下,你可能想靠边站,并直接写入到HTTP响应流,而不是一个局部视图渲染的结果(谐音/视图使用MvcHtmlString / StringWriter的)。要做到这一点,使用Html.RenderPartial帮手。

There are some cases where you might like to step aside and write directly to the HTTP Response stream rather than having a partial view render the results (partials/views use MvcHtmlString/StringWriter). To do so, use the Html.RenderPartial helper.

<div>
  @Html.RenderPartial("_FeaturedProduct")
</div>

谁能告诉我这是什么意思?什么情况下,我可能会喜欢写直接到HTTP响应等。如果我的局部视图只包含一行是这样的:

Can someone tell me what it means? What cases where I might like to write direct to the HTTP Response etc. What if my partial view contains just one line like this:

<h1>Hello</h1>

我应该使用,为什么哪?如果我用其他的,会发生什么?

Which should I use and why? What would happen if I used the other?

以下困惑我更加:使用Html.RenderPartial流媒体图像或在媒体中心或者更快的下载时间是非常重要的元素。

The following confused me even more: "Use Html.RenderPartial for streaming images or other elements that are media-centric or where faster download times are highly important."

推荐答案

请参见下面的响应。

唯一的区别是部分返回一个MvcHtmlString,并且必须
  在里面&LT调用;%=%>,而的RenderPartial returnsvoid并呈现
  直接到视图。

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

如果你看一下源$ C ​​$ C,你会发现它们都调用
  同样的内部方法,传递一个StringWriter的为它渲染到。

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.

如果您想要查看,保存或操纵你会打电话偏
  生成的,而不是将它们写入HTML页面。

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

<一个href=\"http://stackoverflow.com/questions/2729815/what-is-the-difference-if-any-between-html-partialview-model-and-html-render\">What是Html.Partial(视图模型)和Html.RenderPartial(视图模型)在MVC2之间的差额(如果有的话)?

这篇关于Html.Partial或Html.RenderPartial与MVC3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆