MVC Multilevel Catalog Menu-----Simple Simulation
Model----CS
{ Public classClass1 { Public intid{Get;Set;} Public intParentID {Get;Set; } Public intchildID {Get;Set; } Public stringTitle {Get;Set; } }
MVC View----cshtml:
@using Webapplication1.models; @{Viewbag.title=" About"; } ThisArea to provide additional information.</p>@{ varTotallist =NewList<class1> ();//List of all catalogsTotallist.add (Newclass1{ID =1, ParentID =0, title ="Title_1"}); Totallist.add (Newclass1{ID =5, ParentID =0, title ="title_5"}); Totallist.add (Newclass1{ID = A, ParentID =0, title ="Title_12"}); Totallist.add (Newclass1{ID =2, ParentID =1, title ="title_2"}); Totallist.add (Newclass1{ID =3, ParentID =1, title ="Title_3"}); Totallist.add (Newclass1{ID =4, ParentID =1, title ="Title_4"}); Totallist.add (Newclass1{ID =6, ParentID =5, title ="Title_6"}); Totallist.add (Newclass1{ID =7, ParentID =5, title ="title_7"}); Totallist.add (Newclass1{ID =8, ParentID =5, title ="Title_8"}); Totallist.add (Newclass1{ID =9, ParentID =2, title ="Title_9"}); Totallist.add (Newclass1{ID =Ten, ParentID =2, title ="title_10"}); Totallist.add (Newclass1{ID = One, ParentID =2, title ="Title_11"}); Totallist.add (Newclass1{ID = -, ParentID = A, title ="title_13"}); Totallist.add (Newclass1{ID = -, ParentID = A, title ="title_14"}); Totallist.add (Newclass1{ID = the, ParentID = A, title ="title_15"}); Totallist.add (Newclass1{ID = -, ParentID =4, title ="title_16"}); Totallist.add (Newclass1{ID = -, ParentID =4, title ="title_17"}); Totallist.add (Newclass1{ID = -, ParentID =4, title ="title_18"}); foreach(varIteminchtotallist) { <ul>@if (Item.parentid==0) {//If you are a first-level directory<li> @item .title</li>if(Totallist.find (x = X.parentid = = item.id)! =NULL) {@Show (item); } } </ul>}} @helper Show (Class1 item) {varTotallist =NewList<class1> ();//List of all catalogsTotallist.add (NewClass1 {ID =1, ParentID =0, title ="Title_1" }); Totallist.add (NewClass1 {ID =5, ParentID =0, title ="title_5" }); Totallist.add (NewClass1 {ID = A, ParentID =0, title ="Title_12" }); Totallist.add (NewClass1 {ID =2, ParentID =1, title ="title_2" }); Totallist.add (NewClass1 {ID =3, ParentID =1, title ="Title_3" }); Totallist.add (NewClass1 {ID =4, ParentID =1, title ="Title_4" }); Totallist.add (NewClass1 {ID =6, ParentID =5, title ="Title_6" }); Totallist.add (NewClass1 {ID =7, ParentID =5, title ="title_7" }); Totallist.add (NewClass1 {ID =8, ParentID =5, title ="Title_8" }); Totallist.add (NewClass1 {ID =9, ParentID =2, title ="Title_9" }); Totallist.add (NewClass1 {ID =Ten, ParentID =2, title ="title_10" }); Totallist.add (NewClass1 {ID = One, ParentID =2, title ="Title_11" }); Totallist.add (NewClass1 {ID = -, ParentID = A, title ="title_13" }); Totallist.add (NewClass1 {ID = -, ParentID = A, title ="title_14" }); Totallist.add (NewClass1 {ID = the, ParentID = A, title ="title_15" }); Totallist.add (NewClass1 {ID = -, ParentID =4, title ="title_16" }); Totallist.add (NewClass1 {ID = -, ParentID =4, title ="title_17" }); Totallist.add (NewClass1 {ID = -, ParentID =4, title ="title_18" }); <ul>@for (inti =0; i < Totallist.count; i++){ if(Item.id = =Totallist[i].parentid) { <li> @totalList [i].title</li>if(Totallist.find (x = X.parentid = = totallist[i].id)! =NULL) {@Show (totallist[i]); } } } </ul>}
MVC Multilevel Catalog Menu