Dear SO surfers,
I have a route defined as such:
routes.MapRoute(
"CustomerWithScreenName", // Route name
"Customer/{sn}/{action}", // e.g. Customer/KingKong89/Schedule
new { controller = "Customer", action = "Signup", id = "" } // Parameter defaults
);
But when I formulate a link using ActionLink like this:
<%: Html.ActionLink("Click here", "Schedule", "Customer", new { sn = "KingKong89", new { @class="topLink" } )%>
The resulting hyperlink/URL comes out like this:
http://localhost:65071/Customer/Schedule?sn=KingKong89
It works but I expected ActionLink to use the known routes and construct the correct link which would be:
http://localhost:65071/Customer/KingKong89/Schedule
Is my expectation wrong? Is it the parametered URL how it should work?
Note: I don't specify {controller} in the route. I can't seem to mix this route with the more orthodox {controller}{action}{id} route - maybe I should stop trying to be clever and adopt the convention.
Thanks for your help. Luke.
UPDATE
I have a theory that without a proper route (including the {controller} special keyword), I won't be able to make ActionLink produce proper URLs.
So I'm now turning my sights on why this simple route doesn't work:
routes.MapRoute(
"ControllerWithScreenName", // Route name
"{controller}/{sn}/{action}", // e.g. Customer/Dave/Schedule
new { controller = "Customer", action = "Signup", sn = "" } // Parameter defaults
);
As the only route, along with the default "Root", it doesn't play ball. If the controller name is added specifically (as in the first snippet above) it does.
UPDATE 2
Due to time constraints, I'm giving up on my param-before-action style URL and going back to the default controller\action\param - its a small thing in the grand scheme of making progress and not feeling frustrated and depressed.
UPDATE 3
I'm going to uncomment all my smart-ass routes and try using a RouteLink and specify the type of route to use. I think this is the raison d'etre of the RouteLink comment.
UPDATE 4
This is no good. This requires the app has knowledge of the routes to take which means I lose the option to just alter the routing in future and have all the links update automatically.