MVC Html.Partial或Html.Action [英] MVC Html.Partial or Html.Action

查看:137
本文介绍了MVC Html.Partial或Html.Action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的ASP.NET MVC所以请大家多多包涵。我需要建立一个跨多个视图重复的菜单。什么会更好的服务宗旨 Html.Action Html.Partial

I am new to asp.net MVC so please bear with me. I need build a menu that repeats across multiple views. What would better serve the purpose Html.Action OR Html.Partial.

推荐答案

下面是什么,我认为使用Html.Action我的准则或Html.Partial

Here are what I consider my guidelines on using Html.Action or Html.Partial

Html.Partial


  1. 使用,当你呈现的静态内容 Html.Partial

  2. 如果您打算从视图模型传递数据被发送到主视图

Html.Action


  1. 使用 Html.Action 当你真正需要从服务器获取更多数据来填充局部视图

  1. Use Html.Action when you actually need to retrieve additional data from the server to populate the partial view

基本上,如果是静态的,使用 Html.Partial()。如果动态模型独立的数据,使用 Html.Action()。可能有更多的场景,但是这会给你在哪里/如何去一个好主意。 Html.RenderPartial() Html.RenderAction()是上述类似命名的功能互换。

Basically, if is static, use Html.Partial(). If dynamic, model independent data, use Html.Action(). There are probably more scenarios, but this will give you a good idea of where/how to go. Html.RenderPartial() and Html.RenderAction() are interchangeable for the similarly named functions above.

这篇关于MVC Html.Partial或Html.Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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