Sep 27, 2012, 1:51 AM
MVC Razor - Generate menu item dynamically
HI Mates
I am trying to generate menu item dynamically. My idea is to generate the menu item, which comes from database based on specific user roles.
Html.X().Menu()
.Items(i =>
{
i.Add(Html.X().MenuItem()
.Text("Profile")
.Icon(Icon.Magnifier));
i.Add(Html.X().MenuItem()
.Text("Roles")
.Icon(Icon.Wrench)
);
}
I want to load the menu from the buildmenu function! ????
public ActionResult GetMenu()
{
return buildMenu();
}
private Coolite.Ext.Web.Menu buildMenu()
{
Coolite.Ext.Web.Menu SubMenu = new Coolite.Ext.Web.Menu();
IList<Menu> menuCollection = GetMenu();
SubMenu.ID = "SubMenu";
foreach (Menu menu in menuCollection)
{
SubMenuFolder = new Coolite.Ext.Web.MenuItem();
SubMenuFolder.ID = dbRow["vMenuName"].ToString();
SubMenuFolder.Icon = Icon.Folder;
SubMenuFolder.Text = dbRow["vMenuCaption"].ToString();
SubMenu.Items.Add(SubMenuFolder);
}
}
Return SubMenu ;
}
I am trying to generate menu item dynamically. My idea is to generate the menu item, which comes from database based on specific user roles.
Html.X().Menu()
.Items(i =>
{
i.Add(Html.X().MenuItem()
.Text("Profile")
.Icon(Icon.Magnifier));
i.Add(Html.X().MenuItem()
.Text("Roles")
.Icon(Icon.Wrench)
);
}
I want to load the menu from the buildmenu function! ????
public ActionResult GetMenu()
{
return buildMenu();
}
private Coolite.Ext.Web.Menu buildMenu()
{
Coolite.Ext.Web.Menu SubMenu = new Coolite.Ext.Web.Menu();
IList<Menu> menuCollection = GetMenu();
SubMenu.ID = "SubMenu";
foreach (Menu menu in menuCollection)
{
SubMenuFolder = new Coolite.Ext.Web.MenuItem();
SubMenuFolder.ID = dbRow["vMenuName"].ToString();
SubMenuFolder.Icon = Icon.Folder;
SubMenuFolder.Text = dbRow["vMenuCaption"].ToString();
SubMenu.Items.Add(SubMenuFolder);
}
}
Return SubMenu ;
}