# ASP.NET Core ContextMenu Overview

The Telerik UI ContextMenu TagHelper and HtmlHelper for ASP.NET Core are server-side wrappers for the Kendo UI ContextMenu widget.

The ContextMenu displays hierarchical data as a multi-level menu in a popup. It provides rich styling for unordered lists of items, and can be used for both navigation and execution of JavaScript commands.

* [Demo page for the ContextMenu HtmlHelper](https://demos.telerik.com/aspnet-core/menu/context-menu)

* [Demo page for the ContextMenu TagHelper](https://demos.telerik.com/aspnet-core/menu/contextmenu-tag-helper)

## Basic Usage

The following example demonstrates how to define the ContextMenu.

```Razor HtmlHelper
<div id="target">Click to open</div>

@(Html.Kendo().ContextMenu()
    .Name("contextmenu")
    .Target("#target")
    .ShowOn("click")
    .Items(items =>
    {
        items.Add()
            .Text("Furniture") //Add an item with the text "Item1".)
            .Items(children =>{
                children.Add().Text("Sofas");
                children.Add().Text("Chairs");
                children.Add()
                    .Text("Tables")
                    .Items(i =>{
                        i.Add().Text("Dining Tables");
                        i.Add().Text("Coffee Tables");
                    })
                children.Add().Text("Accessories");
            });
        items.Add()
            .Text("Electronics") //Add an item with the text "Item2".)
            .Items(children =>{
                children.Add().Text("TVs");
                children.Add().Text("Laptops");
            });
    })
)
```

```Razor TagHelper
    <div id="target">Right click here</div>
    <kendo-contextmenu name="menu" target="#target" show-on="click">
        <popup-animation>
            <open effects="fade:in" duration="500" />
        </popup-animation>
        <items>
            <menu-item text="Furniture">
                <sub-items>
                    <menu-item text="Sofas"></menu-item>
                    <menu-item text="Chairs"></menu-item>
                    <menu-item text="Tables">
                        <sub-items>
                            <menu-item text="Dining Tables"></menu-item>
                            <menu-item text="Coffee Tables"></menu-item>
                        </sub-items>
                    </menu-item>
                    <menu-item text="Accessories"></menu-item>
                </sub-items>
            </menu-item>
            <menu-item text="Electronics">
                <sub-items>
                    <menu-item text="TVs"></menu-item>
                    <menu-item text="Laptops"></menu-item>
                </sub-items>
            </menu-item>
        </items>
    </kendo-contextmenu>
```

## Configuration

The following example demonstrates the basic configuration of the ContextMenu HtmlHelper and how to get the ContextMenu instance.

```Razor HtmlHelper
<div id="target">Click to open</div>

@(Html.Kendo().ContextMenu()
    .Name("contextmenu")
    .Target("#target")
    .ShowOn("click")
    .Items(items =>
    {
        items.Add().Text("Item 1")
            .ImageUrl(Url.Content("https://demos.telerik.com/kendo-ui/content/shared/icons/sports/baseball.png"))
            .Items(children =>
            {
                children.Add().Text("Top News");
                children.Add().Text("Photo Galleries");
                children.Add().Separator(true);
                children.Add().Text("Videos Records");
                children.Add().Text("Radio Records");
            });
        items.Add().Text("Item 2")
            .ImageUrl(Url.Content("https://demos.telerik.com/kendo-ui/content/shared/icons/sports/golf.png"))
            .Items(children =>
            {
                children.Add().Text("Top News");
                children.Add().Text("Photo Galleries");
                children.Add().Separator(true);
                children.Add().Text("Videos Records");
                children.Add().Text("Radio Records");
            });
        items.Add().Text("Item 3")
            .ImageUrl(Url.Content("https://demos.telerik.com/kendo-ui/content/shared/icons/sports/swimming.png"))
            .Items(children =>
            {
                children.Add().Text("Top News");
                children.Add().Text("Photo Galleries");
            });
    })
    .Animation(animation =>
    {
        animation.Open(fade => fade.Fade(FadeDirection.In));
        animation.Open(open => open.Expand(ExpandDirection.Vertical));         
    })
    .HoverDelay(500)
    .Direction("left")
    .Orientation(ContextMenuOrientation.Horizontal)
    .Events(events => events
        .Open("onOpen")
    )
)

<script type="text/javascript">
    function onOpen() {
    // The Name() of the ContextMenu is used to get its instance.
    var menu = $("#contextmenu").data("kendoContextMenu");
    console.log(menu);
    }
</script>
```

```Razor TagHelper
    <kendo-contextmenu name="contextmenu" target="#target" hover-delay="500"  orientation="ContextMenuOrientation.Horizontal"
        on-open="onOpen">
        <items>
            <menu-item text="Baseball" image-url="@Url.Content("~/shared/icons/sports/baseball.png")">
                <sub-items>
                    <menu-item text="Top News" />
                    <menu-item text="Photo Galleries" />
                    <menu-item separator="true"></menu-item>
                    <menu-item text="Videos Records" />
                    <menu-item text="Radio Records" />
                </sub-items>
            </menu-item>
            <menu-item text="Golf" image-url="@Url.Content("~/shared/icons/sports/golf.png")">
                <sub-items>
                    <menu-item text="Top News" />
                    <menu-item text="Photo Galleries" />
                    <menu-item separator="true"></menu-item>
                    <menu-item text="Videos Records" />
                    <menu-item text="Radio Records" />
                </sub-items>
            </menu-item>
            <menu-item text="Swimming" image-url="@Url.Content("~/shared/icons/sports/swimming.png")">
                <sub-items>
                    <menu-item text="Top News" />
                    <menu-item text="Photo Galleries" />
                </sub-items>
            </menu-item>
        </items>
        <popup-animation >
            <open effects="expand:vertical fade:in"/>
        </popup-animation>
    </kendo-contextmenu>

    <script type="text/javascript">
        function onOpen() {
        // The Name() of the ContextMenu is used to get its instance.
        var menu = $("#contextmenu").data("kendoContextMenu");
        console.log(menu);
        }
    </script>
```

## Functionality and Features

The ContextMenu derives from the Menu component and largely shares the same functionalities, features, and configuration options. To learn more about them, refer to the [Menu Overview](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/menu/overview#functionality-and-features) article.

## Next Steps

* [Getting Started with the ContextMenu](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/menu/contextmenu/getting-started)

* [Using the ContextMenu (Demo)](https://demos.telerik.com/aspnet-core/menu/context-menu)

* [ContextMenu in Razor Pages](https://www.telerik.com/aspnet-core-ui/documentation/html-helpers/navigation/menu/contextmenu/razor-page)

## See Also

* [Using the API of the Menu for ASP.NET Core (Demo)](https://demos.telerik.com/aspnet-core/menu/api)
* [Client-Side API of the ContextMenu](https://docs.telerik.com/kendo-ui/api/ui/contextmenu)
* [Server-Side API of the ContextMenu](https://www.telerik.com/aspnet-core-ui/documentation/api/contextmenu)
* [Knowledge Base Section](https://www.telerik.com/aspnet-core-ui/documentation/knowledge-base)
