Base solution for your next web application
Open Closed

Want to open a view in Modal when clicking on a Menu Item #2022


User avatar
0
jibbar created

For Example, I have a menu as below: Template -- Create New Template -- Template List

If I click on the Sub-Menu "Create New Template" I want to open the page in a modal without redirecting in any URL.

Also, I want to show all the Template list Name as Sub-Menu item just under Template List.

How can be done? Kindly Give suggestion.

Thanks in Advance


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can create menu items without url and when rendering menu in your .cshtml file, add menu name as an attribute to each list item (li). You can add it like " data-menu-item-name='YourMenuItemName' ".

    After doing that, you can select list items and open necessary pages using jQuery.

    You can also add your templates to your menu just before passing your menu to your view.

  • User Avatar
    0
    jibbar created

    How I will call to open the POP up when clicking on a menu item without redirecting to a URL.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You need to include a javascript like that in your Layout file. I haven't tested this code, please check if there is any typing error when you are trying this.

    $(document).ready(function(){
        $("ul.page-sidebar-menu li.nav-item a").click(function(e){
            var $menuItemLink = $(this);
            //here, you need to decide whether open a popup or redirect to href of html a element.
            if(WeNeedToOpenPopup){
                e.preventDefault();
                //open popup here
            }else {
                document.location.href = $menuItemLink.attr("href");
            }
        });
    });