Copied to clipboard

Flag this post as spam?

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


  • Uchenna 9 posts 79 karma points
    May 25, 2018 @ 11:58
    Uchenna
    0

    I have read the documentation on https://our.umbraco.org/documentation/Reference/Routing/custom-controllers

    and from what I understand, you have to create a new controller for each document type you have defined if you want to route hijack. This can be a bit bothersome if you wanted to use a controller for a group of related document.

    The code below is an example of what I want to do

        public class WidgetsController : RenderMvcController
    {
        public ActionResult CtaWidget(RenderModel model)
        {
            return CurrentTemplate(model);
        }
    
        public ActionResult ButtonWidget(RenderModel model)
        {
            return CurrentTemplate(model);
        }
    
        public ActionResult VideoWidget(RenderModel model)
        {
            return CurrentTemplate(model);
        }
    
        public ActionResult ContentCardWidget(RenderModel model)
        {
            return CurrentTemplate(model);
        }
    }
    

    Is this possible? The idea is that, all the different action methods are different document types. I come from a Sitecore background so I was just wondering if the same thing is done.

    Thanks

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 25, 2018 @ 13:44
    Dave Woestenborghs
    0

    Hi

    What you can do is create a base controller for the common doctypes that inherits from RenderMvcController

    And then your actual doctype controller can inherit from that one.

    If that makes any sense

    Dave

  • Uchenna 9 posts 79 karma points
    May 25, 2018 @ 14:07
    Uchenna
    0

    I'm not sure I understand what you mean, could you give a code example? I may understand that better.

  • Dave Woestenborghs 3504 posts 12133 karma points MVP 8x admin c-trib
    May 25, 2018 @ 14:13
    Dave Woestenborghs
    0

    Hi,

    Of course it's hard to give a "correct" solution without knowing exactly what you are trying to do.

    I assume you have a document type called widgets ? And that you use several widgets for rendering them ? But are the widgets actual pages or do you want to render them in a page ?

    Dave

  • Uchenna 9 posts 79 karma points
    May 25, 2018 @ 14:22
    Uchenna
    0

    No, there isn't a document type called widgets.

    I have several document types, and they're called, Cta Widget, Button Widget, Video Widget and Content Card Widget. These widgets are like resuable content components that can only be placed on any page using a Grid Layout.

    I wanted to use route hijacking because I want to execute custom code before displaying the view. But I want to group similar document types to use an arbitrary controller. I don't want to create 5 different controllers for the 5 different widget types. Does that make sense? I want them all in one controller.

    Apologies if I still don't make much sense.

Please Sign in or register to post replies

Write your reply to:

Draft