@{ List<mvcapplicationmenusample.models.menumodel> menuList = ViewBag.Menu; } <ul class="menu"> @foreach (var mp in menuList.Where(p => p.ParentId == 0)){ <li><a href="#">@mp.Name</a> @if( menuList.Count(p=>p.ParentId == mp.Id ) > 0){ @:<ul> } @RenderMenuItem(menuList,mp) @if( menuList.Count(p=>p.ParentId == mp.Id ) > 0){ @:</ul> } </li> } </ul> @helper RenderMenuItem(List<mvcapplicationmenusample.models.menumodel> menuList, MvcApplicationMenuSample.Models.MenuModel mi) { foreach (var cp in menuList.Where(p => p.ParentId == mi.Id)) { //var hlink = "/Home/" + @cp.Name; //var val= @cp.Name.Replace(" ", string.Empty); @:<li> @cp.Name @* val*@ if(menuList.Count(p=>p.ParentId == cp.Id) > 0) { @:<ul> } @RenderMenuItem(menuList,cp) if(menuList.Count(p=>p.ParentId == cp.Id) > 0) { @:</ul> } else { @:</li> } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)