Copied to clipboard

Flag this post as spam?

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


  • João Roque 11 posts 95 karma points
    Feb 14, 2020 @ 10:31
    João Roque
    0

    Need to use standard MVC controller

    Hi,

    In the project I'm working on I'm using telerik kendo ui components, more specifically the editor with image/file upload. This component makes use of a closed source standard MVC controller that allow for file listing / upload. So I can't make it a RenderMVCController nor a SurfaceController, I may only inherit from it and override some methods.

    I've tried this as a way to register the custom MVC routes:

    public class RegisterCustomRouteComposer : ComponentComposer<RegisterCustomRouteComponent>
    { }
    
    public class RegisterCustomRouteComponent : IComponent
    {
        public void Initialize()
        {
            RouteTable.Routes.MapRoute(
               name: "ImageBrowserController",
               url: "imagebrowser/{action}/{id}",
               defaults: new { controller = "ImageBrowser", id = UrlParameter.Optional });
        }
    }
    

    And also:

    public class RegisterHomeControllerComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Register<ImageBrowserController>(null, Lifetime.Request);
        }
    }
    

    But I'm not sure on that last snippet about the null, I had to pass it because I didn't know how to create the "factory" parameter and the example I was going by didn't even have that parameter.

    Is there a simpler way? Or I just need to fix the composer? I'd appreciate some help as I've searched everything and couldn't find any propper answer to accomplish this, everyone always switches to RenderMVCController or SurfaceController and solves their problem, but that is not an option for me.

    Thanks,

    João

  • Marc Goodson 2155 posts 14408 karma points MVP 9x c-trib
    Feb 14, 2020 @ 20:20
    Marc Goodson
    100

    Hi João

    You should be able to register you MVC controller like so?

    public class RegisterHomeControllerComposer : IUserComposer
    {
        public void Compose(Composition composition)
        {
            composition.Register<ImageBrowserController>(Lifetime.Request);
        }
    }
    

    This extension method here: https://github.com/umbraco/Umbraco-CMS/blob/v8/contrib/src/Umbraco.Core/RegisterExtensions.cs#L26

    but in order to take advantage of this extensions, you will need to add

    using Umbraco.Core to your IUserComposer implementation....

    regards

    Marc

  • João Roque 11 posts 95 karma points
    Feb 17, 2020 @ 09:18
    João Roque
    0

    Hi Marc.

    That's exactly it! I had missed the extension method. Thank you very much for you help, it is working now.

Please Sign in or register to post replies

Write your reply to:

Draft