c# - how to iterate through model of two table in foreach loop mvc3 -


i have problem iterating foreach loop in view of custom model.i trying create dynamic menu razor here code:

model:

public class menuctrlmodel  {     public ilist<menu> menu { get; set; }     public ilist<submenu> submenu { get; set; } } 

controller:

    public partialviewresult index()      {         var nuser = datacontext.userlogins.singleordefault(x => x.nvrchrusername == user.identity.name);         string[] menu = nuser.vcrmenu.tostring().split('|').toarray();          string[] submenu = nuser.vcrsubmenu.tostring().split('|').toarray();          menuctrlmodel menuctrl = new menuctrlmodel();          menuctrl.menu = (from varmenu in datacontext.menus            menu.contains( convert.tostring( varmenu.intmenuid ) ) select varmenu).tolist();          menuctrl.submenu=(from varsubmenu in datacontext.submenus   submenu.contains( convert.tostring(varsubmenu.intsubmenu ) ) select varsubmenu ).tolist();     }   

view: giving me error at

**@model ilist<mvcapp.models.menuctrlmodel> @foreach(var xyz in model.select(x=>x.menu))  {      @html.routelink(xyz.select(x=>x.nvcrmenuname), new { controller = xyz.select(x=>x.nvcrlink),action=xyz.select(x=>x.nvcrlink) })}  } ** 

i have tried

@foreach(var xyz in model) 

and when try find menu list model.menu not menu not appearing in intellisense** please suggest how can resolve problem.

thank you.

since model list of menuctrlmodel, each of has menu property, model.select(x=>x.menu) return collection of collections.

i think want loop through each item, loop through menus in each item:

@foreach(var menumodel in model))     @foreach(var menu in menumodel.menu))     

although can't tell how sub-menus linked further that.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -