Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've got this to work thanks to Mystere Man and Nikolay Kostov, thanks guys for your help. I created a custom route which has a dictionary to map between page name and controller, like so;</p> <pre><code>private static readonly IDictionary&lt;string, Type&gt; Map = CreateControllerPageMap(); private static IDictionary&lt;string, Type&gt; CreateControllerPageMap() { var map = new Dictionary&lt;string, Type&gt;(); map.Add("quote1", typeof(EditVehicleController)); map.Add("quote2", typeof(EditProposerController)); map.Add("quote3", typeof(EditAdditionalDriversController)); map.Add("quote4", typeof(EditPolicyController)); return map; } </code></pre> <p>My override for GetRouteData looks like this;</p> <pre><code>public override RouteData GetRouteData(HttpContextBase httpContext) { var routeData = base.GetRouteData(httpContext); SetRouteData(routeData); return routeData; } private static void SetRouteData(RouteData routeData) { var quotePage = routeData.GetRequiredString("quotePage"); var controller = Map[quotePage].Name.Replace("Controller", string.Empty); routeData.Values["controller"] = controller; routeData.Values["action"] = "Edit"; } </code></pre> <p>The final step was just to register the route like this;</p> <pre><code>routes.Add("QuoteJourney", new QuoteJourneyRoute("compare-van-insurance/{quotePage}", new MvcRouteHandler())); </code></pre> <p>That worked fine. However I then found that URLs generated by RedirectToAction were incorrect, because ASP .NET MVC did not know how to map back from controller name and action name to a URL. This was resolved by overriding GetVirtualPath;</p> <pre><code>public override VirtualPathData GetVirtualPath(RequestContext requestContext, RouteValueDictionary values) { var virtualPathData = base.GetVirtualPath(requestContext, values); SetVirtualPath(values, virtualPathData); return virtualPathData; } private static void SetVirtualPath(IDictionary&lt;string, object&gt; values, VirtualPathData virtualPathData) { var controller = values["controller"] + "Controller"; var quotePage = Map.Keys.Single(k =&gt; Map[k] == Map.Values.Single(v =&gt; v.Name == controller)); virtualPathData.VirtualPath = "compare-van-insurance/" + quotePage; } </code></pre> <p>Sorted!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload