Html.Partial VS Html.RenderPartial&安培; Html.Action VS 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
要求写
内部并返回无效
。
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
. The result will be written to the Response
stream during execution/evaluation.
这也适用于 Html.Action
和 Html.RenderAction
。
这篇关于Html.Partial VS Html.RenderPartial&安培; Html.Action VS Html.RenderAction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!