我有一张表赞:
MenuTreeID ParentID MenuName
---------- -------- --------
1 0 Menu No 1
2 1 Menu No 1.1
3 1 Menu No 1.2
4 3 Menu No 1.2.1
5 3 Menu No 1.2.2
6 0 Menu No 2
7 6 Menu No 2.1
8 6 Menu No 2.2
9 1 Menu No 1.3
... ... ... ...
现在我需要关注Unorderlist:
Menu No 1
Menu No 1.1
Menu No 1.2
Menu No 1.2.1
Menu No 1.2.2
Menu No 1.3
Menu No 2
Menu No 2.1
Menu No 2.2
... ... ... ...
如何使用MVC Razor视图引擎编码(cshtml编码)获取它? 我尝试下面的代码:
<ul>
@foreach (ESimSolMVC05.Models.MenuTree oItem in Model)
{
<li>
@oItem.MenuName
@if (oItem.SubItems.Count > 0)
{
@ShowSubItems(oItem.SubItems)
}
</li>
}
</ul>
@helper ShowSubItems(ESimSolMVC05.Models.MenuTrees oSubItems)
{
<ul>
@if (oSubItems.Count > 0)
{
foreach (ESimSolMVC05.Models.MenuTree oTempItem in oSubItems)
{
<li>
@oTempItem.MenuName
@if (oTempItem.SubItems.Count>0)
{
@ShowSubItems(oTempItem.SubItems)
}
</li>
}
}
</ul>
}
这里SubItems意味着当我创建我的集合时,我得到子项目(Select * From Menutree Where ParentID = MenuTreeID)查询。 我的输出UnOrder List是:
**Menu No 1
Menu No 1.1
Menu No 1.2
Menu No 1.1 (Duplicate)
Menu No 1.2 (Duplicate)
Menu No 2
Menu No 2.1
Menu No 2.2
Menu No 1.2.1 (Order not maintain)
Menu No 1.2.2 (Order not maintain)
Menu No 1.3 (Order not maintain)**