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 1 post 71 karma points
    3 days ago
    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 1077 posts 7210 karma points MVP 4x c-trib
    2 days ago
    Marc Goodson
    0

    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

Please Sign in or register to post replies

Write your reply to:

Draft