Search results

Open and close ContextMenu

Open and close the ContextMenu manually whenever required by using the open and close methods. In the following sample, to open the ContextMenu at specified position the open method is used with X and Y coordinates and to close ContextMenu close method can be used.

tagHelper
openclose.cs
<button class='e-btn' id="btnElement">Open ContextMenu</button>
<ejs-contextmenu id="contextmenu" items="ViewBag.menuItems"></ejs-contextmenu>

<script>

    document.getElementById('btnElement').onclick=function() {
      var contextMenuObj = ej.base.getInstance(document.getElementById('contextmenu'), ejs.navigations.ContextMenu)
      contextMenuObj.open(60, 20);
    }

</script>

<style>

button {
  margin: 20px 0 0 5px;
}

</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 OpenClose()
        {
            List<object> menuItems = new List<object>();
            menuItems.Add(new
            {
                text = "Cut"
            });
            menuItems.Add(new
            {
                text = "Copy"
            });
            menuItems.Add(new
            {
                text = "Paste"
            });
            ViewBag.menuItems = menuItems;
            return View();
        }
    }
}