[NOTE: I'm using ASP.NET MVC2 RC2.]
I have URLs like this:
/customers/123/orders/456/items/index
/customers/123/orders/456/items/789/edit
My routing table lists the most-specific routes first, so I've got:
// customers/123/orders/456/items/789/edit
routes.MapRoute(
"item", // Route name
"customers/{customerId}/orders/{orderId}/items/{itemId}/{action}", // URL with parameters
new { controller = "Items", action = "Details" }, // Parameter defaults
new { customerId = @"\d+", orderId = @"\d+", itemId = @"\d+" } // Constraints
);
// customers/123/orders/456/items/index
routes.MapRoute(
"items", // Route name
"customers/{customerId}/orders/{orderId}/items/{action}", // URL with parameters
new { controller = "Items", action = "Index" }, // Parameter defaults
new { customerId = @"\d+", orderId = @"\d+" } // Constraints
);
When I'm in the item "Edit" page, I want a link back up to the "Index" page. So, I use:
ActionLink("Back to Index", "index")
However, because there's an ambient item ID, this results in the URL:
/customers/123/orders/456/items/789/index
...whereas I want it to "forget" the item ID and just use:
/customers/123/orders/456/items/index
I've tried overriding the item ID like so:
ActionLink("Back to Index", "index", new { itemId=string.empty })
...but that doesn't quite work. What that gives me is:
/customers/123/orders/456/items?itemId=789
How can I persuade ActionLink
to "forget" the item ID?
EDIT: fixed question - I was referring to "order" where I meant "item".
EDIT: added detail of why itemId=string.empty doesn't work.