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

How to pop a modal from a NavLink item in NavMenu.razor?

Hi,

I'm new to Blazor but I'm already having struggles popping up a modal when clicking on one of the menu items (NavLink) using the @onclick method. What I'm trying to create is as follows:

My menu has 6 different items, the last item of that is "Sign Out" link. When user clicks on this link a modal should pop up in the center of the total screen(what I got so far is that it appears in sidebar?). How can I achieve this? Where do I create the modal? Whats the best approach to call this modal and make it visible? Can someone help me with this? Thanks in advance!

Niels

1 Reply 1 reply marked as answer

MV Madhan Venkateshan Syncfusion Team June 11, 2020 02:33 PM UTC

Hi Niels Schutte, 
 
Good day to you. 
 
You can use ‘Dialog’ Component to show as a model on ‘ItemSelected’ event of Menu component and on Dialog button click you can perform your action. Please refer the below code snippets and sample link. 
 
Index.razor 
<SfDialog @ref="DialogRef" Target="#wrapper" Width="500px" IsModal="true" ShowCloseIcon="true" Visible="false"> 
    <DialogTemplates> 
        <Header>Header</Header> 
        <Content> <p>Content</p> </Content> 
    </DialogTemplates> 
    <DialogButtons> 
        <DialogButton OnClick="@DlgButtonClick"> 
            <DialogButtonModel Content="OK" IsPrimary="true"></DialogButtonModel> 
        </DialogButton> 
    </DialogButtons> 
</SfDialog> 
@code { 
    SfDialog DialogRef; 
     
 
    public void DlgButtonClick() 
    { 
        // you can perform your action here for dialog button click 
        DialogRef.Hide(); 
    } 
 
    public void MenuItemSelect(Syncfusion.Blazor.Navigations.MenuEventArgs args) 
    { 
        if(args.Item.Text == "Sign out") 
        { 
            DialogRef.Show(); 
        } 
    } 
} 
 
 
 
 
 
Regards, 
Madhan V 


Marked as answer
Loader.
Up arrow icon