# Use Grid with ContextMenu

## Environment

<table>
 <tr>
  <td>Product</td>
  <td>Telerik UI for ASP.NET MVC Grid, <br/>
    Telerik UI for ASP.NET MVC ContextMenu
  </td>
 </tr>
 <tr>
  <td>Product version</td>
  <td>2025.1.227</td>
 </tr>
</table>

## Description

How can I integrate the ContextMenu component into the Grid?

## Solution

You can achieve this requirement using the following implementation:

1. Define an editable Grid:

   ```Razor HtmlHelper
   @(Html.Kendo().Grid<Telerik.Examples.Mvc.Areas.GridContextMenu.Models.Order>()
       .Name("grid")
       .Columns(columns =>
       {
           columns.Bound(p => p.OrderID);
           columns.ForeignKey(p => p.EmployeeID, (System.Collections.IEnumerable) ViewData["employees"], "EmployeeID", "Name");
           columns.Bound(p => p.OrderDescription);
           columns.Bound(p => p.OrderDate).Format("{0:d}");
           columns.Bound(p => p.OrderTotal).Format("{0:c}");
           columns.Bound(p => p.IsCompleted);
           columns.Command(c =>
           {
               c.Edit();
               c.Destroy();
           });
       })
       .ToolBar(toolBar => toolBar.Create())
       .Editable(editable => editable.Mode(GridEditMode.InLine))
       .Pageable()
       .Sortable()
       .Scrollable()
       .Filterable()
       .DataSource(dataSource => dataSource
           .Ajax()
           .ServerOperation(false)
           .Model(model =>
           {
               model.Id(p => p.OrderID);
               model.Field(p => p.OrderID).Editable(false);
           })
           .Create(create => create.Action("Create", "Home").Data("sendCulture"))
           .Destroy(destroy => destroy.Action("Delete", "Home").Data("sendCulture"))
           .Read(read => read.Action("Read", "Home").Data("sendCulture"))
           .Update(update => update.Action("Update", "Home").Data("sendCulture"))
       )
   )
   ```

2. Define the ContextMenu component and handle its `Select` event to handle the selected action:

   ```Razor HtmlHelper
   @(Html.Kendo().ContextMenu()
       .Name("contextMenu")
       .Target("#grid table")
       .Filter("tr")
       .Events(e => e.Select("onSelect"))
       .Items(items =>
       {
           items.Add()
               .Text("Delete").HtmlAttributes(new { @class = "k-grid-delete" });

           items.Add()
               .Text("Edit").HtmlAttributes(new { @class = "k-grid-edit" });
       })
   )
   ```

   ```JS Scripts
       function onSelect(e) {
           var row = $(e.target);
           var grid = $("#grid").data("kendoGrid");
           var item = $(e.item);
           if (item.hasClass("k-grid-delete")) {
               grid.removeRow(row);
           } else {
               grid.editRow(row);
           }
       }
   ```

To review the complete example, refer to the [project on how to use the Grid with the ContextMenu component](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/GridContextMenu) in ASP.NET MVC applications.

## More ASP.NET MVC Grid Resources

* [ASP.NET MVC Grid Documentation](https://www.telerik.com/aspnet-mvc/documentation/html-helpers/data-management/grid/overview)
* [ASP.NET MVC Grid Demos](https://demos.telerik.com/aspnet-mvc/grid/index)
* [ASP.NET MVC Grid Product Page](https://www.telerik.com/aspnet-mvc/grid)
* [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 Grid for ASP.NET MVC](https://docs.telerik.com/kendo-ui/api/ui/grid)
* [Server-Side API Reference of the Grid for ASP.NET MVC](https://docs.telerik.com/aspnet-mvc/api/grid)
* [Telerik UI for ASP.NET MVC Knowledge Base](https://docs.telerik.com/aspnet-mvc/knowledge-base)
