I want to output a menu structure that will look like this
我想输出一个看起来像这样的菜单结构
<ul>
<li>
MenuItemName1
<ul>
<li>Child Item</li>
</ul>
</li>
<li>
MenuItemName2
</li>
</ul>
I have a menuitem class that contains the name, url and children menu items. I would like to create a partial view that renders each item as an unordered list like above and I would call it recursively to go through the entire tree.
我有一个menuitem类,其中包含name,url和children菜单项。我想创建一个局部视图,将每个项目呈现为上面的无序列表,我会递归调用它来遍历整个树。
Is this a bad idea? Will it be very slow?
这是一个坏主意吗?它会非常慢吗?
3 个解决方案
#1
I'm doing this and it doesn't seem particularly slow, but it's not a high volume site. Would be a great place to wire in some caching.
我这样做并没有特别慢,但它不是一个高容量的网站。将是一个很好的地方连接一些缓存。
Check out the answers to my question on the same topic. I think the HTMLHelper extension method might perform a bit better than nested partial views.
查看我对同一主题的问题的答案。我认为HTMLHelper扩展方法可能比嵌套的部分视图执行得更好。
#2
It is always a good idea to be lazy and save yourself some repetitive work.
懒惰总是一个好主意,为自己省去一些重复的工作。
It shouldn't be slower than having a view with all elements directly on it and no partial render calls.
它不应该比拥有直接在其上的所有元素的视图慢,也不应该部分渲染调用。
#3
I'm not sure about MVC but with traditional ASP.Net 2.0 if you nested user controls too deeply you could blow the stack. I saw this happen once at about 10+ levels of nesting.
我不确定MVC但是对于传统的ASP.Net 2.0如果嵌套用户控件太深,你可能会破坏堆栈。我看到这种情况发生在大约10级以上的嵌套中。
#1
I'm doing this and it doesn't seem particularly slow, but it's not a high volume site. Would be a great place to wire in some caching.
我这样做并没有特别慢,但它不是一个高容量的网站。将是一个很好的地方连接一些缓存。
Check out the answers to my question on the same topic. I think the HTMLHelper extension method might perform a bit better than nested partial views.
查看我对同一主题的问题的答案。我认为HTMLHelper扩展方法可能比嵌套的部分视图执行得更好。
#2
It is always a good idea to be lazy and save yourself some repetitive work.
懒惰总是一个好主意,为自己省去一些重复的工作。
It shouldn't be slower than having a view with all elements directly on it and no partial render calls.
它不应该比拥有直接在其上的所有元素的视图慢,也不应该部分渲染调用。
#3
I'm not sure about MVC but with traditional ASP.Net 2.0 if you nested user controls too deeply you could blow the stack. I saw this happen once at about 10+ levels of nesting.
我不确定MVC但是对于传统的ASP.Net 2.0如果嵌套用户控件太深,你可能会破坏堆栈。我看到这种情况发生在大约10级以上的嵌套中。