This question is locked. New answers and comments are not allowed.
Hi,
I am trying to bind a menu to a model class and it works fine when text, controller and action have values, but when I am trying to insert a new menu item without controller it gives me the error. Is there a better way of doing this? Basically I want to add new menu item with child items, but no action for the parent.
this is my Model class:
The view:
In the controller I add more items based on some criteria:
Thanks.
I am trying to bind a menu to a model class and it works fine when text, controller and action have values, but when I am trying to insert a new menu item without controller it gives me the error. Is there a better way of doing this? Basically I want to add new menu item with child items, but no action for the parent.
this is my Model class:
public class MenuModel { public class MenuItem { public int MenuId { get; set; } public string Text { get; set; } public string Controller { get; set; } public string Action { get; set; } public List<MenuItem> ChildItems { get; set; } public MenuItem(int menuId, string text, string controller, string action) { this.MenuId = menuId; this.Text = text; this.Controller = controller; this.Action = action; this.ChildItems = new List<MenuItem>(); } } public string Name { get; set; } public List<MenuItem> MenuItems { get; set; } public MenuModel(string name) { this.Name = name; this.MenuItems = new List<MenuItem>(); } }The view:
<%= Html.Telerik().Menu() .Name("Menu") .Orientation(MenuOrientation.Horizontal) .BindTo((IEnumerable)Model.MenuItems, mappings => { mappings.For<AgdataFtp.WebUI.Models.MenuModel.MenuItem>(binding => binding .ItemDataBound((item, menu) => { item.Text = menu.Text; if (menu.Controller != null) item.ControllerName = menu.Controller; // error appearing in this line if (menu.Action != null) item.ActionName = menu.Action; }) .Children(menu => menu.ChildItems)); }) %>In the controller I add more items based on some criteria:
if ((user.UserRol == "Administrator") || (user.UserRol == "Manager")) { if (user.BusinessGroup.Count > 1) { menuItem = new MenuModel.MenuItem(initialMenu.MenuItems.Count + 1, "Business Group", "", ""); for (int i = 0; i < user.BusinessGroup.Count; i++) { childItem = new MenuModel.MenuItem(i, user.BusinessGroup[i], "Main", "BusinessFolderActions"); menuItem.ChildItems.Add(childItem); } } else initialMenu.MenuItems.Add(new MenuModel.MenuItem(initialMenu.MenuItems.Count + 1, user.BusinessGroup[0], "Main", "BusinessFolderActions")); int lastMenuNumber = initialMenu.MenuItems.Count; menuItem = new MenuModel.MenuItem(++lastMenuNumber, "Settings", "", ""); childItem = new MenuModel.MenuItem(++lastMenuNumber, "Browse Log", "Permissions", "ShowLogFile"); menuItem.ChildItems.Add(childItem); childItem = new MenuModel.MenuItem(++lastMenuNumber, "Permissions", "Permissions", "ExternalUpdate"); menuItem.ChildItems.Add(childItem); childItem = new MenuModel.MenuItem(++lastMenuNumber, "Update Membership", "Permissions", "InternalUpdate"); menuItem.ChildItems.Add(childItem); initialMenu.MenuItems.Add(menuItem); }Thanks.