Porting a RadMenu to ASP.NET Core MVC

1 Answer 120 Views
Menu
Walter
Top achievements
Rank 1
Walter asked on 12 Oct 2023, 09:40 PM

I am porting a WebForms application to ASP.NET Core MVC, and I'm having trouble moving from the RadMenu (Telerik UI for .NET AJAX) to the menu component in Telerik UI for ASP.NET Core. After going down many blind alleys I'm stumped as to how to bind my data (an array of a custom type which includes menu text, target URLs, and more). My menu has a collection of top-level items and some of them have sub-menu items. It seems like this should be pretty straightforward but I can't find an example or documentation that explains how to bind my menu to an array.

I think I need to do something like this:

@(Html.Kendo().Menu()
           .Name("MyMenu")
           .DataTextField("Text")
           .Action(<action>)
           .DataSource(???)
           .Model(model => model.Children("MenuItems"))) <<<--- This came from an example, I don't know what it does)
   )

Can someone point me to a simple example?

 

1 Answer, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 17 Oct 2023, 06:08 PM

Hello Walter,

 

Thank you for writing to us. I hope you are doing well :)

Here is a live sample where you can see the full code:
https://demos.telerik.com/aspnet-core/menu/remote-data-binding

The Menu uses the following settings:

            .DataTextField("Name") // name of the main field
            .DataSource(ds => ds.Read("GetCategories", "Menu") // controller action path
            .Model(model => model.Children("Products"))) // sub-items collection name
And this is the database result:
            var result = northwind.Categories.ToList().Select((category) => 
                new
                {
                    Name = category.CategoryName,
                    Products = northwind.Products
                        .Where((product) => product.CategoryID == category.CategoryID)
                        .Select((product)=> new { Name = product.ProductName })
                }
            );
Products is the collection which will hold the sub-menu items.

I hope this will prove helpful. Feel free to give it a try and do not hesitate to let me know if I made a mistake somewhere or you need more particular and specific example/code. I will be ready to help you with any other inquires you might have.

 

Regards,
Eyup
Progress Telerik

Stay tuned by visiting our public roadmap and feedback portal pages. If you're new to the Telerik family, be sure to check out our getting started resources, as well as the only REPL playground for creating, saving, running, and sharing server-side code.
Tags
Menu
Asked by
Walter
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Share this question
or