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 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.

    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.

  2. Alexander Popov
    Admin
    Alexander Popov avatar
    1416 posts

    Posted 26 Apr 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

    Regards,
    Alexander Popov
    Telerik
     
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
     
  3. Kendo UI is VS 2017 Ready
Back to Top