How do I dynamically add links to each of the items in a Menu binding to remote data?

1 Answer 340 Views
Menu
Lee
Top achievements
Rank 1
Lee asked on 06 Jul 2022, 02:07 PM

Hope I'm asking this question in the right place.

I have this working:

    @(Html.Kendo().Menu()
            .Name("QmsMenu")
            .DataTextField("Title")
            .DataSource(ds => ds.Read("Menu_Read", "Menu")
            .Model(model => model.Children("MenuItems")))
    )

Reference: https://demos.telerik.com/aspnet-core/menu/remote-data-binding

However, I can't figure out how to dynamically add links to each of the items in a Menu binding to remote data.

The payload returned from the server is providing the controller name and controller action method name for each of the menu items. I would like to add these values to the code above enabling a user to click on a menu link and be taken to a different page in the web application.

Would appreciate some help regarding this.

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Aleksandar
Telerik team
answered on 07 Jul 2022, 06:54 AM

Hello Lee,

I have responded to the support question on the same matter and am also posting the response here, for the benefit of the community.

To add links set the DataUrlField in the Menu configuration and build the url based on the available Controller and Action on the server, for example:

View:

@(Html.Kendo().Menu()
            .Name("QmsMenu")
            .DataTextField("Name")
            .DataUrlField("MyUrl")
            .DataSource(ds => ds.Read("Menu_Read", "Home")
            .Model(model => model.Children("MenuItems")))
    )

Server:

        public IActionResult Menu_Read()
        {

            var result = Enumerable.Range(1, 10).Select((x) =>
                 new
                 {
                     Name = "Item " + x,
                     MyUrl = Url.Action("MyAction"+x,"MyController"),
                     MenuItems = Enumerable.Range(1, 5).Select(y => new
                     {
                         Name= "SubItem "+ x+y,
                         MyUrl = Url.Action("MyAction" + y, "MyController"+x),
                     })
                 }
            ); ;

            return Json(result);
        }

 

Regards,
Aleksandar
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Lee
Top achievements
Rank 1
commented on 07 Jul 2022, 05:48 PM

Aleksandar, this worked great! Thank you!
Tags
Menu
Asked by
Lee
Top achievements
Rank 1
Answers by
Aleksandar
Telerik team
Share this question
or