MVC SiteMap - when different nodes point to same action SiteMap.CurrentNode does not map to the correct route
I think it is because you are trying to obtain the route FROM the parameters. Basically, MVC is just trying to GUESS what route you could be referring to.
The correct way would be to handle routes by name. So the sitemap should reference to a Route name rather than the Controller, action, etc.
Addendum - I've got it to work!!:
The big stumbling block:
When using different routes to point at the same controller action, so that one has different nodes, the big problem I had was the following:
YOU MUST GIVE THE DIFFERENT NODES A KEY!!! OTHERWISE THE SITEMAP WON'T RENDER!!
EG, just the route attribute on its own is NOT enough and you MUST give each node that point to the same action a UNIQUE key to distinguish them from each other:
<mvcSiteMapNode title="Edit Staff" area="Admin" controller="EditStaff" route="Admin_AdministratorDetails" action="Start" key="administrators_details" />
<mvcSiteMapNode title="Edit Staff" area="Admin" controller="EditStaff" route="Admin_StaffDetails" action="Start" key="staff_details" />
Once I realised that, it is now plain sailing. Otherwise, all is obscure and obtuse.
NOTE:
In the question, the action that was getting called by different routes was the Process action. I changed that to calls to different actions. But when editing my objects (Solicitors), I couldn't do that, as the editing is done by an MVC Wizard that, like my custom menu builder, I have written and works very well. It just simply wasn't possible (or rather, DRY) to recreate the wizard three times. So I HAD to get my menu higlighting working correctly with different routes pointing at the same action.
No Un-DRY fudges will do. My client doesn't deserve it.
The Solution (see NOTE as to why the actions and routes are different to the question):
The suggestion by Carlos Martinez works, but you need to use Html.RouteLink as opposed to Html.ActionLink, in conjunction with the edited sitemap, that details the routes.
Essentially, in your nodes, you need to use the route attribute:
<mvcSiteMapNode title="Details Active Solicitor" area="Solicitors" controller="EditSolicitor" action="Start" route="Active_Details" key="company_activeSolicitors_details"/>
Then, in your views, instead of action links, you use the RouteLink helper:
@Html.RouteLink("Details", "Active_Details", new { action="Start", controller="EditSolicitor", idSolicitor = item.SolicitorId, returnUrl = Request.RawUrl })
In your route registration file, you can now write routes that call the same action:
context.MapRoute(
"Unprocessed_Details",
"Unprocessed/Edit/{idSolicitor}/{action}",
new { action = "Start", controller = "EditSolicitor", idSolicitor = UrlParameter.Optional }
);
context.MapRoute(
"Inactive_Details",
"Inactive/Edit/{idSolicitor}/{action}",
new { controller = "EditSolicitor", action = "Start", idSolicitor = UrlParameter.Optional }
);
context.MapRoute(
"Active_Details",
"Solicitors/Edit/{idSolicitor}/{action}",
new { controller = "EditSolicitor", action = "Start", idSolicitor = UrlParameter.Optional }
);
As you can see, it is the exact same action that is getting called by the three routes. So long as I specify the route name in the mvcSiteMapNode, the routes are correctly distinguished when my menu is built and the highlighting works as required.
Note on getting befuddled with XML:
I hate XML, deeply and truly. It boggles and befuddles me, especially when I have a cold.
The problem being that adding the route attribute to the mvcSiteMapNodes adds to the potential for befuddlement.
And befuddled I got
I had initially tried Carlos' suggestion, but it didn't work. Not sure what the error was, but went through it with a tooth comb and it is now working. The annoying thing is that I am not sure what I was doing wrong.
Living in Hope:
I hope this documents an albeit fringe aspect of mvcSiteMapNode.