Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Feb 06, 2018 @ 15:41
    Michaël Vanbrabandt
    0

    Fire package controller function after clicking custom menu item

    Hi all,

    I have a BootStrapper class which adds a new menu item on the members menulist.

    I was wondering if its possible to fire a function inside my controller after hitting this menu item, or do we first need to show a dialog which then calls the controller function after hitting another button inside the dialog?

    public class PackageApplicationEventHandler : ApplicationEventHandler
    {
        protected override void ApplicationStarted(
            UmbracoApplicationBase umbracoApplication, 
            ApplicationContext applicationContext)
        {
            TreeControllerBase.MenuRendering += Package_MenuRendering;
        }
    
        private void Package_MenuRendering(TreeControllerBase sender, MenuRenderingEventArgs e)
        {
            // If not rendering menu for the document types, return
            if (sender.TreeAlias != "member") return;
    
            var menuItem = new Umbraco.Web.Models.Trees.MenuItem("package", "Package Item");
            menuItem.Icon = "client";
    
            // Append someting to fire controller function inside 
            // my App_Plugins/Package folder after hitting this menu item
    
            menuItem.SeperatorBefore = true;
    
            e.Menu.Items.Insert(e.Menu.Items.Count, menuItem);
        }
    }
    

    /Michaël

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Feb 06, 2018 @ 16:09
    Dave Woestenborghs
    100

    Hi Michaël,

    I don't think this is possible. But I think you can still execute javascript from the menu. There is a ExecuteLegacyJs function on the menu item : https://github.com/umbraco/Umbraco-CMS/blob/5397f2c53acbdeb0805e1fe39fda938f571d295a/src/Umbraco.Web/Models/Trees/MenuItem.cs#L125

    Dave

  • Michaël Vanbrabandt 863 posts 3348 karma points c-trib
    Feb 06, 2018 @ 17:17
    Michaël Vanbrabandt
    0

    Hi Dave,

    thanks for the intel, I will then launch a new view to do the task.

    /Michaël

Please Sign in or register to post replies

Write your reply to:

Draft