MVC Html.Partial或Html.Action [英] MVC Html.Partial or 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
- 使用,当你呈现的静态内容
Html.Partial
或 - 如果您打算从视图模型传递数据被发送到主视图
Html.Action
- 使用
Html.Action
当你真正需要从服务器获取更多数据来填充局部视图
- 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屋!