Copied to clipboard

Flag this post as spam?

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


  • Damion 62 posts 264 karma points
    Aug 22, 2019 @ 13:26
    Damion
    0

    run a method in a controller for a custon dashboard

    I'm using the following example code to try to route to a controller for a back-end dashboard.

    public class RegisterCustomBackofficeMvcRouteComponent : IComponent
        {
           private readonly IGlobalSettings _globalSettings;
            public RegisterCustomBackofficeMvcRouteComponent(IGlobalSettings globalSettings)
            {
                _globalSettings = globalSettings;
            }
            public void Initialize()
            {           
                RouteTable.Routes.MapRoute("cats", _globalSettings.GetUmbracoMvcArea() + "/backoffice/cats/{action}/{id}", new
                {
                    controller = "cats",
                    action = "meow",
                    id = UrlParameter.Optional
                });
            }
    
            public void Terminate()
            {
                throw new NotImplementedException();
            }
        }
    

    If the controller is called DashboardController with a method GetAllMediaFolders(), should I change the Initialize to:

    public void Initialize()
            {
                RouteTable.Routes.MapRoute("Dashboard", _globalSettings.GetUmbracoMvcArea() + "/backoffice/Dashboard/{action}/{id}", new
                {
                    controller = "Dashboard",
                    action = "GetAllMediaFolders",
                    id = UrlParameter.Optional
                });
    
            }
    

    I though this would be the way to do it but the method is not firing (I want it to fire when the dashboard appears), I can however place a breakpoint on the initialize and see that being hit.

    thanks

  • Jason Elkin 26 posts 203 karma points
    Aug 22, 2019 @ 16:27
    Jason Elkin
    101

    Unless you really need to return a view it's best to use WebApi to create an API and consume it in your dashboard with Angular.

    If you use a controller that inherits from Umbraco.Web.WebApi.UmbracoAuthorizedApiController Umbraco will map the routes for you as per the top of the docs.

Please Sign in or register to post replies

Write your reply to:

Draft