局部视图和渲染局部视图有什么区别? [英] What is difference between partial and render partial view ?
本文介绍了局部视图和渲染局部视图有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在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
推荐答案
- 此方法的结果将直接写入HTTP响应流,这意味着它使用与当前网页/模板中相同的TextWriter对象.
- 此方法返回void.
- 易于使用,无需创建任何动作.
- 当部分视图中的显示数据已经在相应的视图模型中时,RenderPartial方法很有用.
- 例如:在显示文章评论的博客中,我们希望使用RenderPartial方法,因为带有评论的文章信息已经填充在视图模型中.
@{Html.RenderPartial("_Comments");}
- 此方法比Partial方法要快,因为它的结果直接写入响应流中,因此速度很快.
- 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.
- This method returns void.
- Simple to use and no need to create any action.
- RenderPartial method is useful when the displaying data in the partial view is already in the corresponding view model.
- 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");}
- This method is faster than Partial method since its result is directly written to the response stream which makes it fast.
部分HTML
- 将部分视图呈现为HTML编码的字符串.
- 此方法的结果可以存储在变量中,因为它返回字符串类型的值.
- 易于使用,无需创建任何动作.
- 类似于RenderPartial方法,当部分视图中的显示数据已经在相应的视图模型中时,Partial方法也很有用.
- 例如:在显示文章评论的博客中,您可以使用Partial方法,因为带有评论的文章信息已经填充在视图模型中.
@Html.Partial("_Comments")
- Renders the partial view as an HTML-encoded string.
- This method result can be stored in a variable, since it returns string type value.
- Simple to use and no need to create any action.
- Like RenderPartial method, Partial method is also useful when the displaying data in the partial view is already in the corresponding view model.
- 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屋!
查看全文