Sample code for creating MenuItems server side with child elements

2 posts, 0 answers
  1. Joseph
    Joseph avatar
    1 posts
    Member since:
    Dec 2015

    Posted 21 Apr 2016 Link to this post

    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.


    @model IEnumerable<MenuItem>

    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.

  2. Alexander Popov
    Alexander Popov avatar
    1445 posts

    Posted 26 Apr 2016 Link to this post

    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

    Alexander Popov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top