Search results

Open a dialog on popup item click

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

In the following example, Dialog will open while selecting Update... item:

razor
dialogSample-mvc.cs
dialogButton-core.cs
@Html.EJS().Dialog("dialog").Header("Software Update").Content("Are you sure want to update?").Width("250px").Visible(false).Buttons(ViewBag.button).Render()
@Html.EJS().SplitButton("element").Content("Help").Items((IEnumerable<object>)ViewBag.items).Select("onSelect").Render()


<script>
    function onSelect(args) {
        if (args.item.text === 'Update...') {
            ej.base.getComponent(document.getElementById('dialog'), "dialog").show();
        }
    }

    function okBtnClick() {
        ej.base.getComponent(document.getElementById('dialog'), "dialog").hide();
    }

    function cancelBtnClick() {
        ej.base.getComponent(document.getElementById('dialog'), "dialog").hide();
    }
</script>

<style>
    .e-split-btn-wrapper{
        margin: 20px 20px 5px 5px;
    }
</style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Syncfusion.EJ2.SplitButtons;
using Syncfusion.EJ2.Popups;

namespace EJ2CoreSampleBrowser.Controllers.Button
{
    public partial class ButtonController : Controller
    {
        public class ButtonModel
        {
            public string content { get; set; }
            public string cssClass { get; set; }
            public bool isPrimary { get; set; }
            public string Click { get; set; }

        }

        public ActionResult SplitButton()
        {
            List<object> items = new List<object>();
            items.Add(new
            {
                text = "Help"
            });
            items.Add(new
            {
                text = "About"
            });
            items.Add(new
            {
                text = "Update..."
            });
        
            ViewBag.items = items;
    
            List<DialogDialogButton> buttons = new List<DialogDialogButton>() { };
            buttons.Add(new DialogDialogButton() { Click = "okBtnClick", ButtonModel = new ButtonModel() { content = "OK", isPrimary = true } });
            buttons.Add(new DialogDialogButton() { Click = "cancelBtnClick", ButtonModel = new ButtonModel() { content = "Cancel", isPrimary = true } });
            ViewBag.button = buttons;
            return View();
        }
    }
}
public ActionResult DialogButton()
{
    List<object> buttons = new List<object>() { };
    buttons.Add(new
    {
        isPrimary = true,
        cssClass = "e-flat",
        content = "ok",
        click = "okBtnClick"
    });
    buttons.Add(new
    {
        isPrimary = true,
        cssClass = "e-flat",
        content = "cancel",
        click = "cancelBtnClick"
    });
    ViewBag.DialogButtons = buttons;
    return View();
}