We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Ability to call an action when when MenItem clicked

Thread ID:

Created:

Updated:

Platform:

Replies:

146681 Aug 13,2019 11:53 PM UTC Apr 6,2021 07:07 AM UTC Blazor 9
loading
Tags: Menu Bar
Dominick Marciano
Asked On August 13, 2019 11:53 PM UTC

I am trying to implement a menu bar, however I need the ability for some of the menu items to open a modal window.  I notice that the MenuItem class has a Text and Url property but it doesn't appear to have any event handlers.  Is it possible to specify an action when certain menu items are clicked vs. just navigating to another page?

Sangeetha Priya Murugan [Syncfusion]
Replied On August 14, 2019 08:26 AM UTC

Hi Dominick, 

Thank you for contacting Syncfusion support. 

We have checked your reported requirement and it can be achievable in Menu by using ItemSelected event as like in the below code example. 

CODE SNIPPETS: 

<EjsMenu Items="@menuItems"> 
    <MenuEvents ItemSelected="onSelect"></MenuEvents> 
</EjsMenu> 
<div id="target"> 
    <EjsDialog @ref="DialogObj" Target="#target" Height="270px" Width="500px" ShowCloseIcon="true" @bind-Visible="@Visibility"> 
        ..// 
    </EjsDialog> 
    </div> 
 
@code{ 
    EjsDialog DialogObj; 
    public bool Visibility { get;set; } = false; 
    private List<MenuItem> menuItems = new List<MenuItem>{ 
            new MenuItem 
            { 
                Text = "File", 
                Items = new List<MenuItem> 
                { 
                    new MenuItem { Text= "Open" },  
                    new MenuItem { Text= "Navigate", Url="counter" },  // Url property, for navigating to counter page. 
                } 
            }, 
             ..// 
    }; 
 
    private void onSelect(MenuEventArgs args) 
    { 
        if (args.Item.Text == "Open"// To check the selected item text 
            DialogObj.Show();  // To open the modal dialog. 
    } 
    } 

For your convenience, we have prepared the sample based on our requirement. Please find the link below. 


Could you please check the above sample and get back to us, if you need any further assistance on this. 

Regards, 
Sangeetha M 


j
Replied On January 12, 2020 09:15 AM UTC

This is nice, I used this.

Saranya Dhayalan [Syncfusion]
Replied On January 13, 2020 05:05 AM UTC

Hi Dominick, 
 
Thanks for the update 
 
Please let us know, if you need any further assistance on this.  
 
Regards, 
Saranya D 


Philippe
Replied On March 31, 2021 09:03 PM UTC

Your sample don't work

I try all your method, nothing working

Aravinthan Seetharaman [Syncfusion]
Replied On April 1, 2021 10:13 AM UTC

Hi Philippe, 
 
We have checked your query. We cannot reproduce your reported issue in our latest version v19.1.0.54. For your reference we have prepared code snippet and Sample here. 
 
Index.razor 
@using Syncfusion.Blazor.Navigations 
 
<div class="control-section"> 
    <div class="menu-control"> 
        <SfMenu TValue="MenuItem"> 
            <MenuItems> 
                <MenuItem Text="File"> 
                    <MenuItems> 
                        <MenuItem Text="Open"></MenuItem> 
                        <MenuItem Text="Save"></MenuItem> 
                        <MenuItem Separator="true"></MenuItem> 
                        <MenuItem Text="Exit"></MenuItem> 
                    </MenuItems> 
                </MenuItem> 
 
                <MenuItem Text="Edit"> 
                    <MenuItems> 
                        <MenuItem Text="Cut" ></MenuItem> 
                        <MenuItem Text="Copy" ></MenuItem> 
                        <MenuItem Text="Paste"></MenuItem> 
                    </MenuItems> 
                </MenuItem> 
 
                <MenuItem Text="View"> 
                    <MenuItems> 
                        <MenuItem Text="Toolbars"> 
                            <MenuItems> 
                                <MenuItem Text="Menu Bar"></MenuItem> 
                                <MenuItem Text="Bookmarks Toolbar"></MenuItem> 
                                <MenuItem Text="Customize"></MenuItem> 
                            </MenuItems> 
                        </MenuItem> 
                        <MenuItem Text="Zoom"> 
                            <MenuItems> 
                                <MenuItem Text="Zoom In"></MenuItem> 
                                <MenuItem Text="Zoom Out"></MenuItem> 
                                <MenuItem Text="Reset"></MenuItem> 
                            </MenuItems> 
                        </MenuItem> 
                        <MenuItem Text="Full Screen"></MenuItem> 
                    </MenuItems> 
                </MenuItem> 
                <MenuItem Text="Tools"> 
                    <MenuItems> 
                        <MenuItem Text="Spelling & Grammar"></MenuItem> 
                        <MenuItem Text="Customize"></MenuItem> 
                        <MenuItem Separator="true"></MenuItem> 
                        <MenuItem Text="Options"></MenuItem> 
                    </MenuItems> 
                </MenuItem> 
                <MenuItem Text="Help"></MenuItem> 
            </MenuItems> 
            <MenuEvents ItemSelected="Select" TValue="MenuItem"></MenuEvents> 
        </SfMenu> 
 
    </div> 
</div> 
 
@code { 
    private void Select(MenuEventArgs<MenuItem> args) 
    { 
        // Your code here. 
    } 
} 
 
 
 
If you are still facing the issue, kindly share the below details. 
 
·        If possible, try to reproduce the reported issue in provided sample or share the issue reproducible sample. 
·        Please share us the video demonstration of this issue. 
·        Please share us the Syncfusion Package Version. 
 
Please provide the above requested information, based on that we will check and provide you a better solution quickly. 
 
Regards, 
Aravinthan S 


Philippe
Replied On April 3, 2021 08:55 PM UTC

I just try it same message

      Unhandled exception in circuit 'poIko7koj_Qto1SGaWQ6fd1QPACE3mYdvTIpiHweU9U'.
      System.InvalidCastException: Unable to cast object of type 'Microsoft.AspNetCore.Components.EventCallback`1[Syncfusion.Blazor.Navigations.MenuEventArgs`1[ProMobileWeb.MenuGauche+DataModel]]' to type 'Microsoft.AspNetCore.Components.EventCallback`1[Syncfusion.Blazor.Navigations.MenuEventArgs`1[Syncfusion.Blazor.Navigations.MenuItemModel]]'.
         at Syncfusion.Blazor.Internal.SfBaseUtils.InvokeEvent[T](Object eventFn, T eventArgs)
         at Syncfusion.Blazor.Navigations.Internal.CreateMenuItem`2.ItemClickHandler(TItem item, EventArgs e, Boolean isEnterKey)
         at Syncfusion.Blazor.Navigations.Internal.CreateMenuItem`2.<>c__DisplayClass36_0.<<BuildRenderTree>b__1>d.MoveNext()
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
         at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task taskToHandle)
Microsoft.AspNetCore.Components.Server.Circuits.CircuitHost: Error: Unhandled exception in circuit 'poIko7koj_Qto1SGaWQ6fd1QPACE3mYdvTIpiHweU9U'.


Some parts of my code

                            <SfMenu CssClass="dock-menu"
                                    Items="@menuItems"
                                    Orientation="Orientation.Vertical"
                                    ShowItemOnClick="true"
                                    EnablePersistence="true"
                                    TValue="DataModel">
                                <MenuEvents ItemSelected="Select"
                                            TValue="DataModel">
                                </MenuEvents>
                            </SfMenu>

@code {
    SfSidebar sidebar;
    public bool SidebarToggle = false;

    private void Select(MenuEventArgs<DataModel> args)
    {
        Close();
    }

    public class DataModel
    {
        public string Id { get; set; }
        public string Text { get; set; }
        public string IconCss { get; set; }
        public string Url { get; set; }
        public string ParentId { get; set; }
    }
    private List<DataModel> menuItems = new List<DataModel>();


    protected override void OnInitialized()
    {
        base.OnInitialized();
        menuItems.Add(new DataModel
        {
            Id = "01",
            Text = @languageContainer.Keys["Articles"],
            IconCss = "fas fa-file-word"
        });
        menuItems.Add(new DataModel
        {
            Id = "0101",
            Text = @languageContainer.Keys["VoirEdition"],
            IconCss = "fas fa-file-word",
            Url = "admarticles",
            ParentId = "01"
        });
        menuItems.Add(new DataModel
        {
            Id = "0102",
            Text = @languageContainer.Keys["AjouterUnArticle"],
            IconCss = "fas fa-plus-square",
            Url = "admarticlesdetail/0",
            ParentId = "01"
        });
        menuItems.Add(new DataModel
        {
            Id = "02",
            Text = @languageContainer.Keys["Endroits"],
            IconCss = "fas fa-map-marker-alt"
        });

EVERYTHING IS OK BUT I CAN CAPTURE THE ONSELECT TO CLOSE THE SIDEBAR

Aravinthan Seetharaman [Syncfusion]
Replied On April 5, 2021 11:26 AM UTC

 
Thanks for the update. 
 
We have checked your query. We suspect that this issue occurred due to giving custom type while using self-referential data structure. In self-referential item defining method we have used strongly typed value MenuItemModel to populate submenu items. So, we can resolve this issue by providing strongly typed value MenuItemModel as TValue in MenuEvents and in arguments. Please refer the below code snippet. 
 
Index.razor 
 
@using Syncfusion.Blazor.Navigations 
 
<SfMenu CssClass="dock-menu" 
        Items="@menuItems" 
        Orientation="Orientation.Vertical" 
        ShowItemOnClick="true" 
        EnablePersistence="true" 
        TValue="DataModel"> 
    <MenuEvents ItemSelected="Select" 
                TValue="MenuItemModel"> 
    </MenuEvents> 
</SfMenu> 
@code { 
    public bool SidebarToggle = false; 
 
    private void Select(MenuEventArgs<MenuItemModel> args) 
    { 
        //Your code here. 
    } 
 
    public class DataModel 
    { 
        public string Id { get; set; } 
        public string Text { get; set; } 
        public string IconCss { get; set; } 
        public string Url { get; set; } 
        public string ParentId { get; set; } 
    } 
    private List<DataModel> menuItems = new List<DataModel>(); 
 
 
    protected override void OnInitialized() 
    { 
        base.OnInitialized(); 
        menuItems.Add(new DataModel 
        { 
            Id = "01", 
            Text = "One", 
            IconCss = "fas fa-file-word" 
        }); 
        menuItems.Add(new DataModel 
        { 
            Id = "0101", 
            Text = "Two", 
            IconCss = "fas fa-file-word", 
            Url = "admarticles", 
            ParentId = "01" 
        }); 
        menuItems.Add(new DataModel 
        { 
            Id = "0102", 
            Text = "Three", 
            IconCss = "fas fa-plus-square", 
            Url = "admarticlesdetail/0", 
            ParentId = "01" 
        }); 
        menuItems.Add(new DataModel 
        { 
            Id = "02", 
            Text = "Four", 
            IconCss = "fas fa-map-marker-alt" 
        }); 
    } 
} 
 
 
 
Could you please check the above details, and get back to us, if you need assistance on this. 
 
Regards, 
Aravinthan S

Philippe
Replied On April 5, 2021 09:04 PM UTC

Thank you everything working now

Sangeetha Priya Murugan [Syncfusion]
Replied On April 6, 2021 07:07 AM UTC

Hi Philippe, 
 
Thank you for your update. 
 
We are happy to hear that your issue has been resolved. Kindly get back to us if you need any further assistance. 
 
Regards, 
Sangeetha M 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon