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

How to Bind Action & Controller to Menu from DB

1 Answer 47 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.
ankit
Top achievements
Rank 1
ankit asked on 09 Dec 2010, 05:09 AM
I have following code which generates nice MVC menu. However, I don't know how can I bind Controller and Action to menu. I have searched many forums, couldn't find answer. 

Note : I am using my controller to produce menu from Database. I have column in my table for Controller and Action.

<%= Html.Telerik().Menu()
        .Name("Menu")
        .Orientation(MenuOrientation.Vertical)
        .BindTo(Model.Where(x => x.ParentID == null).ToList(), mappings =>
        {
            mappings.For<Dialog.Telstra.DataObject.Menu>(binding => binding
                    .ItemDataBound((item, ParentMenu) =>
                    {
                        item.Text = ParentMenu.Name;
                         
                    })
                    .Children(ParentMenu => ParentMenu.Menu1));
            mappings.For<Dialog.Telstra.DataObject.Menu>(binding => binding
                     .ItemDataBound((item, ChildMenu) =>
                     {
                         item.Text = ChildMenu.Name;
                     }));
        })
%>

1 Answer, 1 is accepted

Sort by
0
ankit
Top achievements
Rank 1
answered on 09 Dec 2010, 05:59 AM
I found solution myself.
<%= Html.Telerik().Menu()
        .Name("Menu")
        .Orientation(MenuOrientation.Vertical)
        .BindTo(Model.Where(x => x.ParentID == null).ToList(), mappings =>
        {
            mappings.For<Dialog.Telstra.DataObject.Menu>(binding => binding
                    .ItemDataBound((item, ParentMenu) =>
                    {
                        item.Text = ParentMenu.Name;
                        if( ParentMenu.ActionName != null)
                            item.ActionName = ParentMenu.ActionName;
                        if (ParentMenu.ControllerName != null)
                            item.ControllerName = ParentMenu.ControllerName;
                    })
                    .Children(ParentMenu => ParentMenu.Menu1));
            mappings.For<Dialog.Telstra.DataObject.Menu>(binding => binding
                     .ItemDataBound((item, ChildMenu) =>
                     {
                         item.Text = ChildMenu.Name;
                         item.ActionName = ChildMenu.ActionName;
                         item.ControllerName = ChildMenu.ControllerName;
                     }));
        })
%>
Tags
Menu
Asked by
ankit
Top achievements
Rank 1
Answers by
ankit
Top achievements
Rank 1
Share this question
or