Try our conversational search powered by Generative AI!

EPiServer 8 MVC action names

Vote:
 

Hi,

Is there anyway to map the {action} part of Url onto a different action name?

So I want to map the Url /site-search/late-availability on to an action called LateAvailability in my page controller?

Right now it seems that only /site-search/lateavailability works and I've tried decorating my actions with ActionName and Route attributes but neither work.

Cheers

#143871
Feb 02, 2016 16:53
Vote:
 

Hi, Neil,

I'd suggest taking an easier approach if that's possible for you. 

You'd create a new page type called LateAvailabilityPage and then create it under SearchPage with any name you want. Then you do what you'd want to do in LateAvailability action, in Index action of the new page.

Not sure if this suits your requirements, but is way easier and more "CMS way".

BR,

Marija

#143921
Feb 03, 2016 12:56
Vote:
 

I suggest going with Marijas way...it's also possible to extend the common routing by registrating new routes and using EPiServers routing and routed events like this:

protected override void RegisterRoutes(System.Web.Routing.RouteCollection routes)
{
base.RegisterRoutes(routes);
EPiServer.Web.Routing.ContentRoute.RoutingContent+=ContentRoute_RoutingContent;
}

void ContentRoute_RoutingContent(object sender, RoutingEventArgs e)
{
if (e.RoutingSegmentContext.RemainingPath == "Test-Action")
{
e.RoutingSegmentContext.RemainingPath = "TestAction";
}
}

#143923
Feb 03, 2016 13:08
Vote:
 

Many thanks for the replies.

I think I'll take Marija's advice and break the tabs into separate pages.

I did find a solution however based upon another forum post - I applied a ExistingActionRouteConstraintWrapper around the exisiting ExistingActionRouteConstraints in the route table and if a Match failed, replaced "-" in the action name and retried the Match with the original ExistingActionRouteConstraint.

    public class ExistingActionRouteConstraintWrapper : IContentRouteConstraint
    {
        private readonly ExistingActionRouteConstraint _original;

        public ExistingActionRouteConstraintWrapper(ExistingActionRouteConstraint original)
        {
            this._original = original;
        }

        public bool Match(Route route, SegmentContext segmentContext, string parameterName)
        {
            // If orignal cant be match, 
            if (!_original.Match(route, segmentContext, parameterName))
            {
                var action = segmentContext.RouteData.Values[parameterName] as string ?? string.Empty;
                segmentContext.RouteData.Values[parameterName] = action.Replace("-", string.Empty);
            }

            var result = _original.Match(route, segmentContext, parameterName);
            // Try again (with possible action modified)
            return result;
        }
    }

Cheers

#143926
Feb 03, 2016 13:18
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* 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.