Home > Net >  How to generate the menu recursive RAZOR pages
How to generate the menu recursive RAZOR pages

Time:02-15

As title, I want to razor page generated tree menu, the following database data
 
ID MENU_NAME PARENT_ID URL ICON ORDER
Zero NULL NULL system 1
Other NULL NULL set 1 2
3 1 User/User management Index NULL 3
4 test set 2 OtherTest/Index NULL 4


The following code is the code for the front desk, but can only generate 2 levels of menus, cannot generate multi-stage, a great god give a idea how to generate multilevel menu
 
@ the if (menus!=null)
{
Foreach (var module in menus. OrderBy (x=& gt; X.o. RDER.) Where (o=& gt; O.P ARENT_ID=="0"))
{





    • @ foreach (var menu in menus. OrderBy (x=& gt; X.o. RDER.) Where (item=& gt; Item. The PARENT_ID==module. ID))
      {


    • @ menu. MENU_NAME


    • }



  • }
    }

    CodePudding user response:

    You the @ foreach is not necessary to write, control directly recursive call myself to go,
    •  Tags:  
    • C#
    • Related