This is a migrated thread and some comments may be shown as answers.

[Solved] "value" cannot be null or empty, Error qhen binding Menu

1 Answer 37 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Laura
Top achievements
Rank 1
Laura asked on 02 Jun 2011, 07:42 PM
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:


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.

1 Answer, 1 is accepted

Sort by
0
Laura
Top achievements
Rank 1
answered on 02 Jun 2011, 09:19 PM
Already fixed it.
Thanks.
Tags
Menu
Asked by
Laura
Top achievements
Rank 1
Answers by
Laura
Top achievements
Rank 1
Share this question
or