Html.Partial 与 Html.RenderPartial &Html.Action 与 Html.RenderAction [英] Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

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

问题描述

在ASP.NET MVC中,有什么区别:

In ASP.NET MVC, what is the difference between:

  • Html.PartialHtml.RenderPartial
  • Html.ActionHtml.RenderAction
  • Html.Partial and Html.RenderPartial
  • Html.Action and Html.RenderAction

推荐答案

Html.Partial 返回一个字符串.Html.RenderPartial 在内部调用 Write 并返回 void.

Html.Partial returns a String. Html.RenderPartial calls Write internally and returns void.

基本用法是:

// Razor syntax
@Html.Partial("ViewName")
@{ Html.RenderPartial("ViewName");  }

// WebView syntax
<%: Html.Partial("ViewName") %>
<% Html.RenderPartial("ViewName"); %>

在上面的代码段中,两个调用都会产生相同的结果.

In the snippet above, both calls will yield the same result.

虽然可以将 Html.Partial 的输出存储在一个变量中或从一个方法中返回它,但不能Html.RenderPartial.

While one can store the output of Html.Partial in a variable or return it from a method, one cannot do this with Html.RenderPartial.

结果将在执行/评估期间写入Response流.

The result will be written to the Response stream during execution/evaluation.

这也适用于 Html.ActionHtml.RenderAction.

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

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