Multiple routes to a single controller action

Vote:
 

Hi folks,

I was wondering if it was possible - and if so, how might it be written - to attach multiple, dynamic routes to a single controller action. And as a bonus, could this be driven by CMS property values?

My scenario is: I have a controller action - let's call it "EngControllerAction" - on a multi-language site that I access via the route `/en-gb/forms/controller/EngControllerAction`. The "forms/controller" parts are slugs in my content tree.

I would like to be able to access that action in, say, my French site variant using a suitably translated route e.g. `fr-fr/les-forms/le-controller/FreControllerAction`. I know I can change the slugs in the translated page, but the action controller name is proving a challenge.

I'm aware of potentially using a `[Route()]` decorator but I'm not entirely sure how to format that. Also, if it were in any way possible, we'd like to make the action aliases configurable within the CMS to allow content editors to change if they wish to do so.

Any advice or guidance much appreciated...

#267423
Nov 26, 2021 14:00
Vote:
 

Assuming EngControllerAction refers to a page in the CMS site tree.

Optimizely page routing overrides MVC for any controller inheriting from: EPiServer.Web.Mvc.PageController<T> where T : PageData

Optimizely routing will map each localised version of the URL to the same Action.

#267424
Nov 26, 2021 14:03
Vote:
 

Ah - no. There are several actions on the page - it's a multi-step wizard. So, `/en-gb/forms/controller/EngControllerAction` is one end-point - where "controller" = typeof ControllerPage.

I'll be wanting to call `/en-gb/forms/controller/EngControllerSecondAction` & `/en-gb/forms/controller/EngControllerThirdAction`, with the ability to change all of those final action parts to a localised (CMS configured?) alternative.

#267425
Nov 26, 2021 14:06
Vote:
 

Get ya now!

The Route MVC attribute wont work with CMS routing to the best of my knowledge.

A Partial Router for this page type is worth considering as you can customise the routing:  How To Set-Up A Partial Router - Jon D Jones

In the Partial Router you would need to map the expected translated strings to the desired action method. You could manage these as a CMS setting on the page type

 

#267426
Edited, Nov 26, 2021 15:04
Vote:
 

Avoiding routing customisations and agreeing language agnostic naming conventions for steps is worth considering :)

#267427
Nov 26, 2021 15:19
Vote:
 

Hi Sam,

I would take a look at using a Partial Router.  https://world.optimizely.com/documentation/developer-guides/CMS/routing/partial-routing/

Using this you have access to the segments after the content segment, at which point you can then control the behaviour, this doesn't have to relate to specific actions on your controller.

Hope this helps

Andy

#267429
Nov 26, 2021 16:22
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.