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.
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 ?
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.
Controller Route Hijacking
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
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
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
I'm not sure I understand what you mean, could you give a code example? I may understand that better.
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
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.
is working on a reply...