# Open Window from Menu Item Click by Using Ajax

## 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 use a Telerik UI for ASP.NET MVC Menu item click to open a Telerik UI for ASP.NET MVC Window?

## Solution

1. Declare the Menu component.
2. Handle the [`Select`](https://www.telerik.com/aspnet-mvc/documentation/api/kendo.mvc.ui.fluent/menueventbuilder#selectsystemstring) event of the Menu.
3. In the event handler, get the `id` attribute of the current item.
4. Conditionally check if the `id` is the expected one (**openWindow**).
5. Implement an [Ajax request](https://api.jquery.com/jQuery.ajax/) to an Action Method, which is specified in the Menu item.
6. In the Action Method, return a Partial View with the Window.

```Razor HtmlHelper
    @{Html.Kendo().Menu()
          .Orientation(MenuOrientation.Horizontal)
          .Name("applicationMenu")
          .Items(menu => menu.Add().Text("Home").Items(homeMenu =>
              {
                  homeMenu.Add().Text("Show Window").Action("RenderWindow", "Home").HtmlAttributes(new { id = "openWindow" });
              }))
          .Events(e => e.Select("onSelect"))
          .Render();
    }
```

```JavaScript
    <script type="text/javascript">
        function onSelect(e) {
    
            var itemId = $(e.item).attr("id");
    
            // Check if the menu item it the one, which must request the Partial View with the Window.
            if (itemId == "openWindow") {
                var url = $(e.item).find("a").attr("href");
                // Stop the link from redirecting to another page.
                e.preventDefault();
                // Request the Partial View with the Window.
                $.ajax({
                    url: url,
                    success: function (data) {
                        $("#main").append(data);
                    }
                });
            }
        }
    </script>
```

```C# Controller
    public IActionResult Index()
    {
        return View();
    }
    public ActionResult RenderWindow()
    {
        return PartialView("ShowWindow");
    }
```

```Razor PartialView
    <script type="text/javascript">
    	 // Destroy the Window after close to allow the opening of multiple Windows.
    	 function onClose(e) {
    		 itemForDelete = $(this.element);
    		 this.destroy();
    		 itemForDelete.remove();
    	 }
    </script>



    @(Html.Kendo()
    		.Window()
    		.Name("window")
    		.Title("My Window Title")
    		.Content(@<text>This is the content of a window, opened with ajax.</text>)
    		.Modal(true)
    		.Actions(a => a.Close())
    		.Draggable()
    		.Resizable()
    		.Width(400)
    		.Height(300)
    		.Events(e => e.Close("onClose"))
    )
```

For the complete implementation of the suggested approach, refer to the [ASP.NET MVC project on how to open a Window when a specified Menu item is clicked](https://github.com/telerik/ui-for-aspnet-mvc-examples/tree/master/Telerik.Examples.Mvc/Telerik.Examples.Mvc/Areas/MenuOpenWindowWithAjax).

## 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)
