Search results

Open a dialog on ContextMenu item click

This section explains about how to open a dialog on ContextMenu item click. This can be achieved by handling dialog open in select event of the ContextMenu.

In the following sample, Dialog will open while clicking Save As... item:

razor
dialog.cs
<div id="contextmenutarget">Right click/Touch hold to open the ContextMenu </div>
@Html.EJS().ContextMenu("contextmenu").Target("#contextmenutarget").Items((IEnumerable<object>)ViewBag.items).Select("itemSelect").Render()
@Html.EJS().Dialog("dialog").Content("This file can be saved as PDF").Visible("visible").Buttons(ViewBag.DialogButtons).Target("#contextmenutarget").Width("200px").Height("110px").Position("position").Render()

<script>

    var position = {X: 100, Y: 100};

    var visible = false;

    function dlgButtonClick() {
        var dialogObj = document.getElementById('dialog').ej2_instances[0];
        dialogObj.hide();
    }

    function itemSelect(args) {
        var dialog = document.getElementById("dialog").ej2_instances[0]
        dialog.show();
    }

</script>

<style>

#contextmenutarget {
    border: 1px dashed;
    height: 250px;
    padding: 10px;
    position: relative;
    text-align: center;
    color: gray;
    line-height: 17;
    font-size: 14px;
}

</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

namespace WebApplication1.Controllers
{
    public class ContextMenuController : Controller
    {
        public IActionResult Dialog()
        {
            List<object> menuItems = new List<object>();
            menuItems.Add(new
            {
                text = "Back"
            });
            menuItems.Add(new
            {
                text = "Forward"
            });
            menuItems.Add(new
            {
                text = "Reload"
            });
            menuItems.Add(new
            {
                separator= true
            });
            menuItems.Add(new
            {
                text = "Save As..."
            });
            menuItems.Add(new
            {
                text = "Print"
            });
            menuItems.Add(new
            {
                text = "Cast"
            });
            ViewBag.menuItems = menuItems;
            return View();
        }
    }
}