局部视图和渲染局部视图有什么区别? [英] What is difference between partial and render partial view ?

查看:164
本文介绍了局部视图和渲染局部视图有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net MVC中非常新,请告诉我应该在哪里使用局部视图,在哪里应该渲染局部视图.预先感谢

I am very new in asp.net MVC kindly let me know where is should use partial view and where i should Render Partial view . Thanks in advance

推荐答案

Html.RenderPartial

  1. 此方法的结果将直接写入HTTP响应流,这意味着它使用与当前网页/模板中相同的TextWriter对象.
  2. 此方法返回void.
  3. 易于使用,无需创建任何动作.
  4. 当部分视图中的显示数据已经在相应的视图模型中时,RenderPartial方法很有用.
  5. 例如:在显示文章评论的博客中,我们希望使用RenderPartial方法,因为带有评论的文章信息已经填充在视图模型中. @{Html.RenderPartial("_Comments");}
  6. 此方法比Partial方法要快,因为它的结果直接写入响应流中,因此速度很快.
  1. This method result will be directly written to the HTTP response stream means it used the same TextWriter object as used in the current webpage/template.
  2. This method returns void.
  3. Simple to use and no need to create any action.
  4. RenderPartial method is useful when the displaying data in the partial view is already in the corresponding view model.
  5. For example : In a blog to show comments of an article, we would like to use RenderPartial method since an article information with comments are already populated in the view model. @{Html.RenderPartial("_Comments");}
  6. This method is faster than Partial method since its result is directly written to the response stream which makes it fast.

部分HTML

  1. 将部分视图呈现为HTML编码的字符串.
  2. 此方法的结果可以存储在变量中,因为它返回字符串类型的值.
  3. 易于使用,无需创建任何动作.
  4. 类似于RenderPartial方法,当部分视图中的显示数据已经在相应的视图模型中时,Partial方法也很有用.
  5. 例如:在显示文章评论的博客中,您可以使用Partial方法,因为带有评论的文章信息已经填充在视图模型中. @Html.Partial("_Comments")
  1. Renders the partial view as an HTML-encoded string.
  2. This method result can be stored in a variable, since it returns string type value.
  3. Simple to use and no need to create any action.
  4. Like RenderPartial method, Partial method is also useful when the displaying data in the partial view is already in the corresponding view model.
  5. For example: In a blog to show comments of an article, you can use Partial method since an article information with comments are already populated in the view model. @Html.Partial("_Comments")

这篇关于局部视图和渲染局部视图有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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