Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC4
Please help convert the following code from Razor to asp.net MVC:
@{
    List<mvcapplicationmenusample.models.menumodel> menuList = ViewBag.Menu;
}
        <ul class="menu">  
    
@foreach (var mp in menuList.Where(p =&gt; p.ParentId == 0)){
    
<li><a href="#">@mp.Name</a> 
        @if( menuList.Count(p=&gt;p.ParentId == mp.Id ) &gt; 0){
            @:<ul>
        }  
        
        @RenderMenuItem(menuList,mp)
       
        @if( menuList.Count(p=&gt;p.ParentId == mp.Id ) &gt; 0){
            @:</ul>
        }
       
 </li>
}
</ul>
 
@helper RenderMenuItem(List<mvcapplicationmenusample.models.menumodel> menuList, MvcApplicationMenuSample.Models.MenuModel mi)
{
    foreach (var cp in menuList.Where(p =&gt; p.ParentId == mi.Id))
    {
        //var hlink = "/Home/" + @cp.Name;
     //var val=   @cp.Name.Replace(" ", string.Empty);
        @:<li>
        @cp.Name
    @* val*@
      if(menuList.Count(p=&gt;p.ParentId == cp.Id) &gt; 0)
        {
           @:<ul>  
        }
        
        @RenderMenuItem(menuList,cp)
      if(menuList.Count(p=&gt;p.ParentId == cp.Id) &gt; 0)
      {
          @:</ul>
      }
      else
      {
          @:</li>
      }
    }
}
Posted 14-Jan-13 2:52am
sp1786668
Edited 14-Jan-13 4:48am
(no name)498.9K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 240
1 Kamal Rocks 184
2 PIEBALDconsult 150
3 BillWoodruff 148
4 Jochen Arndt 135
0 OriginalGriff 5,695
1 DamithSL 4,506
2 Maciej Los 4,007
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 14 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100