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

Sample code for creating MenuItems server side with child elements

1 Answer 126 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Joseph
Top achievements
Rank 1
Joseph asked on 21 Apr 2016, 04:15 PM

I need to create a list of menu items server side and then bind to the kendo menu, but I am unable to create items with child items.

View:

@model IEnumerable<MenuItem>
 
@(Html.Kendo().Menu()
          .Name("Menu")
          .BindTo(Model))

I was unable to find a way to make childOne and childTwo children of the parent menuItem and added to the allMenuItems list

The allMenuItems is what I am passing to the View

var parent = new MenuItem() {Text = "Parent"};
var childOne = new MenuItem() { Text = "Child 1", ActionName = "Foo", ControllerName="Bar" };
var childTwo = new MenuItem() { Text = "Child 2", ActionName = "Foo2", ControllerName = "Bar" };
 
var allMenuItems = new List<MenuItem>();

I need some sample code showing how to build this list server side.

Thank you.

1 Answer, 1 is accepted

Sort by
0
Alexander Popov
Telerik team
answered on 26 Apr 2016, 07:37 AM
Hi Joseph,

I would recommend checking our offline demos, which are located in the UI for ASP.NET MVC installation path, under the \wrappers\aspnetmvc\Examples\VS2012 directory. 
The files you would be interested in are:
  • Areas\razor\Views\menu\modelbinding.cshtml
  • Controllers\Menu\ModelBindingController.cs

Regards,
Alexander Popov
Telerik
 
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
 
Tags
Menu
Asked by
Joseph
Top achievements
Rank 1
Answers by
Alexander Popov
Telerik team
Share this question
or