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

Binding action to menu

6 Answers 998 Views
Menu
This is a migrated thread and some comments may be shown as answers.
ShareDocs
Top achievements
Rank 1
ShareDocs asked on 03 Jun 2013, 03:55 PM
Hi,
I'm trying to understand how to bind an action from the Db to the kendo menu. 
in all the demos I saw there is and Item.add().text().action("action","controller");

but if I bind to Db then I have:
Item.Text = "Some Text";

how should I attach the action method to the menu? (what should be the right side of the item.Action = ?)
I would also like your opinion as to the way to store it in the Db (if there is any best practice regrding this matter).

thank you

6 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 05 Jun 2013, 09:50 AM
Hi,

You can either use the ActionName and ControllerName properties:

item.ActionName = "Action";
item.ControllerName = "Controller";
or the Action method:
item.Action("Action", "Controller", null);
Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ShareDocs
Top achievements
Rank 1
answered on 06 Jun 2013, 04:22 PM
Hi,
I tried it but the menu doesnt responds and i don't get anything on fiddler too...

is there anything to pay attention when using actions? (I don't get an error, just a menu that does not redirect me :( )

UPDATE:
I managed to get it to work.
I've set the parent mapping action and controller and it's now working (why I can't set it through the childs if the childs is what I want to get the action?)


0
Daniel
Telerik team
answered on 10 Jun 2013, 08:43 AM
Hello Lior,

I am not sure what could be causing the described behavior. Could you provide the code you are using?

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
ShareDocs
Top achievements
Rank 1
answered on 10 Jun 2013, 04:05 PM
what part of the code do you want?

this is the view
@model IEnumerable<EladFI.Domain.Entities.Key_MenuItems>
 
 
@(Html.Kendo().Menu()
      .Name("Menu") //The name of the menu is mandatory. It specifies the "id" attribute of the widget.
      .BindTo(Model , mappings =>
      {
          mappings.For<EladFI.Domain.Entities.Key_MenuItems>(binding => binding //define first level of menu
              .ItemDataBound((item, category) => //define mapping between menu item properties and the model properties
                  {
                  item.Text = category.Menu_Title;
                  item.ImageUrl = category.Menu_Image ?? "";
                  
                  if (category.Action != null)
                  {
                      item.ActionName = category.Action.Split('|')[0];
                      item.ControllerName = category.Action.Split('|')[1];
                  }
                  })
              .Children(category => category.ChildMenuItems.Where(x => x.Is_Active && x.Action !=null))); //define which property of the model contains the children
           
          mappings.For<EladFI.Domain.Entities.Key_MenuItems>(binding => binding
              .ItemDataBound((item, product) =>
              {
                  item.Text = product.Menu_Title;
              }));
      })
      
           
)

this is the Key_MenuItems entity:

public class Key_MenuItems
    {
        [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity), Key()]
        public int ID { get; set; }
 
        public string Menu_Title { get; set; }
 
        public int? Parent_ID { get; set; }
 
        public string Action { get; set; }
 
        public int Menu_Order { get; set; }
 
        public bool Is_Active { get; set; }
 
        public string Menu_Image { get; set; }
 
        public bool QA_Only { get; set; }
 
        public bool Is_Blank { get; set; }
 
        public virtual Key_MenuItems Parent { get; set; }
 
        public virtual ICollection<Key_MenuItems> ChildMenuItems { get; set; }
    }

this is the layout which contains the calling to the controller method that brings the partialView:

<div class="float-right">
            @{Html.RenderAction("Menu", "Menu");}
           </div>

Hope you'll find the reason... 
0
Daniel
Telerik team
answered on 12 Jun 2013, 12:01 PM
Hello Lior,

The same type is specified for both mappings. The Menu will automatically bind the children on all levels for homogeneous data and so the second mapping will not be taken into account. If the action should not be used for the top level items then you should the approach that it seems you are already using and set the action and controller configuration only when needed.

Regards,
Daniel
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Accepted
ShareDocs
Top achievements
Rank 1
answered on 12 Jun 2013, 07:20 PM
I understand now,
thank you
Tags
Menu
Asked by
ShareDocs
Top achievements
Rank 1
Answers by
Daniel
Telerik team
ShareDocs
Top achievements
Rank 1
Share this question
or