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:

tagHelper
dialog.cs
<div id="contextmenutarget">Right click/Touch hold to open the ContextMenu </div>
<ejs-contextmenu id="contextmenu" target="#contextmenutarget" items="@ViewBag.menuItems" select="itemSelect"></ejs-contextmenu>
<ejs-dialog id="dialog" content="This file can be saved as PDF" visible="false" position='@new Syncfusion.EJ2.Popups.DialogPositionData() { X= "100" , Y= "100" }' target="#contextmenutarget" width="200px" height="110px">
    <e-dialog-buttons>
        <e-dialog-dialogbutton buttonModel="@ViewBag.DialogButtons" click="dlgButtonClick"></e-dialog-dialogbutton>
    </e-dialog-buttons>
</ejs-dialog>

<script>
    function dlgButtonClick() {
        var dialogObj = ej.base.getInstance(document.getElementById('dialog'), ejs.popups.Dialog);
        dialogObj.hide();
    }

    function itemSelect() {
        var dialog = ej.base.getInstance(document.getElementById('dialog'), ejs.popups.Dialog);
        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();
        }
    }
}