Html.Partial VS Html.RenderPartial&安培; Html.Action VS Html.RenderAction [英] Html.Partial vs Html.RenderPartial & Html.Action vs Html.RenderAction

查看:149
本文介绍了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 and Html.RenderPartial
  • Html.Action and Html.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屋!

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