Html.Partial 与 Html.RenderPartial &Html.Action 与 Html.RenderAction [英] Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction
问题描述
在ASP.NET MVC中,有什么区别:
In ASP.NET MVC, what is the difference between:
Html.Partial
和Html.RenderPartial
Html.Action
和Html.RenderAction
Html.Partial
andHtml.RenderPartial
Html.Action
andHtml.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.Action
和 Html.RenderAction
.
这篇关于Html.Partial 与 Html.RenderPartial &Html.Action 与 Html.RenderAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!