# Handle Unique Identifiers with Menu Items

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Menu</td>
 </tr>
 <tr>
  <td>Product Version</td>
  <td>Created with version 2024.4.1112</td>
 </tr>
</table>

## Description

How can I set custom identifiers to the Telerik UI for ASP.NET MVC Menu items and implement custom logic when the respective item is clicked?

## Solution

Commonly, you are required to handle custom identifiers with `click` handlers or, as in this case, by using the [client-side `Select`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/menueventbuilder#selectsystemstring) event of the component.

To provide for the functionality, the Menu mainly uses the HTML elements that are rendered, so you can use custom HTML attributes to serve as unique identifiers.

In this way, you can programmatically:

* Identify the clicked item.
* Utilize values that are specific to the item other than text.
* Remove a specific item from the Menu by identifying it through an attribute.
* Run a custom logic for particular items.

The following example demonstrates how to handle a custom command attribute to accomplish specific application requirements, such as the ones mentioned in the above list.

```Razor HtmlHelper
    @(Html.Kendo().Menu()
        .Name("menu")
        .Items(items => {
            items.Add()
                .Text("Command 1")
                .HtmlAttributes(new { data_command = "command1" });

            items.Add()
                .Text("Command 2")
                .HtmlAttributes(new { data_command = "command2" });

            items.Add()
                .Text("Remove Command 2")
                .HtmlAttributes(new { @class = "remove-command", data_removecommand = "command2" });
        })
        .Events(events => events.Select("onSelect"))
    )
```

```JavaScript
    <script>
        function onSelect(ev) {
            var clickedItem = $(ev.item);
            var command = clickedItem.data("command"); // Select the value of the "data-command" attribute to identify the clicked Menu item.

            if (command) { // Execute custom logic based on the clicked Menu item.
                alert(command);
            }
        }

        $(document).ready(function(){
            $(".remove-command").click(function(ev){
                var commandToRemove = $(ev.target).parent("li").data("removecommand");
                removeCommand(commandToRemove);
            })
        })

        function removeCommand(command){
            $("#menu").data("kendoMenu").remove("[data-command='" + command + "']"); // Remove the Menu item.
        }
    </script>
```

## More ASP.NET MVC Menu Resources

* [ASP.NET MVC Menu Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/navigation/menu/overview)

* [ASP.NET MVC Menu Demos](https://demos.telerik.com/aspnet-mvc/menu)

* [ASP.NET MVC Menu Product Page](https://www.telerik.com/aspnet-mvc/menu)

* [Telerik UI for ASP.NET MVC Video Onboarding Course (Free for trial users and license holders)](https://www.telerik.com/aspnet-mvc/documentation/getting-started/video-onboarding)

* [Telerik UI for ASP.NET MVC Forums](https://www.telerik.com/forums/aspnet-mvc)

## See Also

* [Client-Side API Reference of the Menu for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/menu)

* [Server-Side API Reference of the Menu for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/menu/api)

* [Telerik UI for ASP.NET MVC Breaking Changes](https://www.telerik.com/aspnet-mvc/documentation/backwards-compatibility/2023-backwards-compatibility)

* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
