Search results

Icons and Sub menu items

Icons

The menu item contains an icon/image in it to provide a visual representation of an action. To place the icon on a menu item, set the iconCss property with the required icon CSS. By default, the icon is positioned at the left of the menu item. In the following sample, the icons of File and Edit menu items and Open, Save, Cut, Copy,and Paste sub menu items are added using the iconCss property.

razor
Icon.cs
@Html.EJS().Menu("menu").Items(ViewBag.menuItems).Render()
<style>
    body {
    margin-top: 100px;
    text-align: center;
}
@@font-face {
    font-family: 'e-menu';
    src:
    url(data:application/x-font-ttf;charset=utf-8;base64,AAEAAAAKAIAAAwAgT1MvMjvJSpgAAAEoAAAAVmNtYXBsm2feAAABpAAAAGxnbHlmmEcyrQAAAiQAAAWIaGVhZBJ0bwcAAADQAAAANmhoZWEHmQNyAAAArAAAACRobXR4I0AAAAAAAYAAAAAkbG9jYQaGB+4AAAIQAAAAFG1heHABGACaAAABCAAAACBuYW1lc0cOBgAAB6wAAAIlcG9zdJbKd4kAAAnUAAAAfQABAAADUv9qAFoEAAAA//4D6gABAAAAAAAAAAAAAAAAAAAACQABAAAAAQAAhka7o18PPPUACwPoAAAAANe2FRwAAAAA17YVHAAAAAAD6gPqAAAACAACAAAAAAAAAAEAAAAJAI4ABQAAAAAAAgAAAAoACgAAAP8AAAAAAAAAAQPrAZAABQAAAnoCvAAAAIwCegK8AAAB4AAxAQIAAAIABQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAUGZFZABA5anohgNS/2oAWgPqAJYAAAABAAAAAAAABAAAAAPoAAAD6AAAA+gAAAPoAAAD6AAAA+gAAAPoAAAD6AAAAAAAAgAAAAMAAAAUAAMAAQAAABQABABYAAAADgAIAAIABuWp5bPluefo6CLohv//AADlqeWy5bnn6Ogi6IX//wAAAAAAAAAAAAAAAAABAA4ADgAQABAAEAAQAAAABQAGAAcACAABAAIAAwAEAAAAAACsASoBRAGwAhICUAKEAsQABAAAAAAD6gNZAD8AfwCDAI0AAAEzHw0dAQ8OLw8/DiMzHw0dAQ8OLw8/DgMhAyEBIRU3EyUVBQMjA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pY29uc0ZvbnQgZ2VuZXJhdGVkIHVzaW5nIFN5bmNmdXNpb24gTWV0cm8gU3R1ZGlvd3d3LnN5bmNmdXNpb24uY29tACAAZQAtAGkAYwBvAG4AcwBSAGUAZwB1AGwAYQByAGUALQBpAGMAbwBuAHMAZQAtAGkAYwBvAG4AcwBWAGUAcgBzAGkAbwBuACAAMQAuADAAZQAtAGkAYwBvAG4AcwBGAG8AbgB0ACAAZwBlAG4AZQByAGEAdABlAGQAIAB1AHMAaQBuAGcAIABTAHkAbgBjAGYAdQBzAGkAbwBuACAATQBlAHQAcgBvACAAUwB0AHUAZABpAG8AdwB3AHcALgBzAHkAbgBjAGYAdQBzAGkAbwBuAC4AYwBvAG0AAAAAAgAAAAAAAAAKAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJAQIBAwEEAQUBBgEHAQgBCQEKAA1zaG9wcGluZy1jYXJ0B2VkaXQtMDUMZmlsZS1vcGVuLTAxDGZpbGUtdGV4dC0wMQNDdXQFUGFzdGUEQ29weQZTZWFyY2gAAAAAAA==) format('truetype');
    font-weight: normal;
    font-style: normal;
}
.em-icons {
    font-family: 'e-menu';
    font-style: normal;
    font-variant: normal;
    font-weight: normal;
    line-height: 1;
    text-transform: none;
}

.e-file::before {
    content: '\e886';
}

.e-edit::before {
    content: '\e822';
}

.e-cut::before {
    content: '\e5a9';
}

.e-copy::before {
    content: '\e5b3';
}

.e-paste::before {
    content: '\e5b2';
}

.e-open::before {
    content: '\e885';
}

.e-save::before {
    content: '\e954';
}
</style>
// GET: Icons
public ActionResult IconFeatures()
{
    List<object> menuItems = new List<object>();
    menuItems.Add(new
    {
        text = "File",
        iconCss = "em-icons e-file",
        items = new List<object>()
                {
                    new { text = "Open", iconCss= "em-icons e-open" },
                    new { text = "Save", iconCss= "e-icons e-save" },
                    new { separator = true },
                    new { text = "Exit" }
                }
    });
    menuItems.Add(new
    {
        text = "Edit",
        iconCss = "em-icons e-edit",
        items = new List<object>()
                {
                    new { text = "Cut", iconCss= "em-icons e-cut" },
                    new { text = "Copy", iconCss= "em-icons e-copy" },
                    new { text = "Paste", iconCss= "em-icons e-paste" }
                }
    });
    menuItems.Add(new
    {
        text = "View",
        items = new List<object>()
                {
                    new { text = "Toolbar" },
                    new { text = "Sidebar" },
                    new { text = "Fullscreen" }
                }
    });
    menuItems.Add(new
    {
        text = "Tools",
        items = new List<object>()
                {
                    new { text = "Spelling & Grammar" },
                    new { text = "Customize" },
                    new { text = "Options" }
                }
    });
    menuItems.Add(new
    {
        text = "Go"
    });
    menuItems.Add(new
    {
        text = "Help"
    });

    ViewBag.menuItems = menuItems;
    return View();
}

Navigation in Menu is used to navigate to the other web page when a menu item is clicked. It can be achieved by providing a link to the menu item using the url property. In the following sample, the Navigation URL is added to sub menu items using the url property.

razor
Navigation.cs
<script>
function beforeItemRender(args) {
    if (args.item.url) {
        // To open url in blank page.
        args.element.getElementsByTagName('a')[0].setAttribute('target', '_blank');
    }
}
</script>

@Html.EJS().Menu("menu").Items(ViewBag.menuItems).BeforeItemRender("beforeItemRender").Render()

<style>
    body {
        margin-top: 100px;
        text-align: center;
    }
</style>
// Menu Navigation
public ActionResult MenuNavigation()
{
    List<object> menuItems = new List<object>();
    menuItems.Add(new
    {
        text = "Appliances",
        items = new List<object>()
                {
                    new { text= "Washing Machine", url= "https://www.google.com/search?q=washing+machine"},
                    new {text= "Air Conditioners", url= "https://www.google.com/search?q=air+conditioners" }
                }
    });
    menuItems.Add(new
    {
        text = "Mobile",
        items = new List<object>()
                {
                    new { text= "Headphones", url= "https://www.google.com/search?q=headphones" },
                    new { text= "Memory Cards", url= "https://www.google.com/search?q=memory+cards" },
                    new { text= "Power Banks", url= "https://www.google.com/search?q=power+banks" }
                }
    });
    menuItems.Add(new
    {
        text = "Entertainment",
        items = new List<object>()
                {
                    new { text= "Televisions", url= "https://www.google.com/search?q=televisions" },
                    new { text= "Home Theatres", url= "https://www.google.com/search?q=home+theatres" },
                    new { text= "Gaming Laptops", url= "https://www.google.com/search?q=gaming+laptops" }
                }
    });
    menuItems.Add(new
    {
        text = "Fashion",
        url = "https://www.google.com/search?q=fashion"
    });
    menuItems.Add(new
    {
        text = "Offers",
        url = "https://www.google.com/search?q=offers"
    });

    ViewBag.menuItems = menuItems;
    return View();
}

Multilevel nesting

The Menu supports multiple level nesting, and it can be achieved by mapping the items property inside the parent menuItems. In the following sample, three-level nesting of menu has been provided.

razor
Nesting.cs
@Html.EJS().Menu("menu").Items(ViewBag.menuItems).Render()

<style>
    body {
        margin-top: 100px;
        text-align: center;
    }
</style>
// Menu Multi Level
public ActionResult MultiLevelNesting()
{
    List<object> menuItems = new List<object>();
    menuItems.Add(new
    {
        text = "Fashion",
        items = new List<object>()
        {
            new {
                text = "Men Fashion",
                items = new List<object>()
                {
                    new {
                        text = "Personal Care",
                        items = new List<object>()
                        {
                            new { text = "Trimmers" },
                            new { text = "Shavers" }
                        }
                    },
                    new {
                        text = "Clothing",
                        items = new List<object>()
                        {
                            new { text = "Shirts" },
                            new { text = "Jackets" },
                            new { text = "Track Suits" }
                        }
                    },
                    new { text = "Footwear"}
                }
            },
            new {
                text = "Women Fashion",
                items = new List<object>()
                {
                    new {
                        text = "Clothing",
                        items = new List<object>()
                        {
                            new { text = "Kurtas" },
                            new { text = "Salwars" },
                            new { text = "Sarees" }
                        }
                    },
                    new {
                        text = "Jewellery",
                        items = new List<object>()
                        {
                            new { text = "Nosepins" },
                            new { text = "Anklets" }
                        }
                    }
                }
            }
        }
    });
    menuItems.Add(new
    {
        text = "Home & Living",
        items = new List<object>()
        {
            new {
                text = "Washing Machine",
                items = new List<object>()
                {
                    new { text = "Fully Automatic" },
                    new { text = "Semi Automatic" }
                }
            },
            new {
                text = "Air Conditioners",
                items = new List<object>()
                {
                    new { text = "Inverter ACs" },
                    new { text = "Split ACs" }
                }
            }
        }

    });
    menuItems.Add(new
    {
        text = "Accessories",
    });
    menuItems.Add(new
    {
        text = "Sports",
    });
    menuItems.Add(new
    {
        text = "Gaming",
    });

    ViewBag.menuItems = menuItems;
    return View();
}

You can achieve multi level nesting with data source by mapping name of the child items to the children sub-property of fields property. For more information, refer to the data source binding section.

See Also