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

[Solved] moving from asp.net menu to mvc menu and cannot figure out binding.

4 Answers 42 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.
Lee Saunders
Top achievements
Rank 1
Lee Saunders asked on 19 Jan 2012, 10:04 PM
Hello,

I've got an asp.net webpage that has a telerik menu on it.

I bind to a flat table that is dynamically built.  It looks like this:

        var tblMyMenu = new DataTable();
 
        tblMyMenu.Columns.Add("ID");
        tblMyMenu.Columns.Add("ParentID");
        tblMyMenu.Columns.Add("Url");
        tblMyMenu.Columns.Add("Text");


Then I fill the table.

Then I bind the table to the menu like this:

        mainMenu.DataSource = tblMyMenu;
        mainMenu.DataFieldID = "ID";
        mainMenu.DataFieldParentID = "ParentID";
        mainMenu.DataTextField = "Text";
        mainMenu.DataNavigateUrlField = "Url";
        mainMenu.DataBind();

Since the binding of Hierarchical menus in MVC seems to be nothing like ASP.Net, I need some help trying to bind this to a MVC Menu.

Thanks

4 Answers, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 23 Jan 2012, 10:52 AM
Hello Lee,


All the information you need to successfully bind your model the the Menu is covered in our online demo.
If you have any questions for concrete setting(s) do not hesitate to ask.

All the best,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Lee Saunders
Top achievements
Rank 1
answered on 30 Jan 2012, 06:11 PM
Petur,

Actually, I do not find this to be the case in your demo.

Your demo is seems to be very simple and does not seem to come close to handling my issue.

Your demo deals with a set of simple parent-child entities (Categories and the Products in each category)

The call to northwind.Categories returns a set of Category entites each with a set of Products(EntitySet<Product>).  This is a simple two level non-self referencing heirarchy - almost not a heirarchy at all.  In your demo, the depth is known and your binding clearly is setup for that.

My data is a self referencing set of objects with no set depth.  Your demo has no examples that support this.

L. Lee Saunders
0
Petur Subev
Telerik team
answered on 31 Jan 2012, 02:44 PM
Hello again Lee,

Basically dealing with self referencing set of objects is almost the same.
e.g. Northwind Employees (each employee may have a manager which is again an employee).
//...
.BindTo(Model, mappings =>
                {
                    mappings.For<Employee>(binding => binding
                            .ItemDataBound((item, employee) =>
                            {
                                item.Text = String.Format("{0} {1}", employee.FirstName, employee.LastName);                               
                            })
                            .Children(employee => employee.Employees));
                })
You need to pass the top level of items in your hierarchy as Model and all the sub menus will be generated accordingly.
 This online example shows the binding configuration in such scenario (this is TreeView but the BindTo configuration uses the same settings).
I hope this helps.

Regards,
Petur Subev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Lee Saunders
Top achievements
Rank 1
answered on 17 Feb 2012, 06:08 PM
Sorry for taking so long to reply.

Thank you for the help, this is exactly what I needed. And, it works exactly as promised.

(Now, I just have to get my data in the correct format!  But, of course thats my issue :-) )

Thanks again,

Lee
Tags
Menu
Asked by
Lee Saunders
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Lee Saunders
Top achievements
Rank 1
Share this question
or