加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – Html.Partial或Html.RenderPartial与MVC3?

发布时间:2020-12-15 20:10:29 所属栏目:asp.Net 来源:网络整理
导读:即使看到以下解释,我完全感到困惑. div @Html.Partial("_FeaturedProduct")/div 部分视图可以在布局页面中显示(或者使用MVC 2/3 / ASPX,主页面)以及常规视图. 在某些情况下,您可能希望将其直接写入HTTP Response流,而不是部分视图呈现结果(部分/视图使用MvcH
即使看到以下解释,我完全感到困惑.
<div>
  @Html.Partial("_FeaturedProduct")
</div>

部分视图可以在布局页面中显示(或者使用MVC 2/3 / ASPX,主页面)以及常规视图.

在某些情况下,您可能希望将其直接写入HTTP Response流,而不是部分视图呈现结果(部分/视图使用MvcHtmlString / StringWriter).为此,请使用Html.RenderPartial帮助器.

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

有人可以告诉我这是什么意思吗?什么情况下,我可能想直接写入HTTP响应等.如果我的部分视图只包含一行如下:

<h1>Hello</h1>

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

以下让我更加困惑:“使用Html.RenderPartial流式传输图像或其他以媒体为中心的元素或更快的下载时间非常重要.”

解决方法

请参阅下面的回应.

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.

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读