I have two routes set up in my application:
routeCollection.MapRoute("CustomerActivity",
"Customer/{id}",
new { controller = "CustomerActivity", action = "DisplayDetails" },
new { id = @"^\d$" });
routeCollection.MapRoute("CustomerSearch",
"Customer/{*pathInfo}",
new
{
controller = "CustomerSearch",
action = "DisplaySearch"
});
Incoming Urls are correctly routed to the right controller/action pairing. However in the view I need to generate an Anchor to view the details of the customer thus:
@Html.ActionLink(Model.Name, "DisplayDetails", "CustomerActivity", new { id = Model.Id }, null)
The problem with this is it doesn't actually pick any of the routes up; I believe this is because of the constraint on the CustomerActivity route.
I've also tried using the RouteLink without much luck:
@Html.RouteLink(Model.Name, "CustomerActivity", new { id = Model.Id })
I can't take out the constraint on CustomerActivity as this is what stops everything falling into that route.
Adding a copy of CustomerActivity without the constraint to the end seems to resolve the problem, but I'm less than impressed:
routeCollection.MapRoute("CustomerActivity",
"Customer/{id}",
new { controller = "CustomerActivity", action = "DisplayDetails" },
new { id = @"^\d$" });
routeCollection.MapRoute("CustomerSearch",
"Customer/{*pathInfo}",
new
{
controller = "CustomerSearch",
action = "DisplaySearch"
});
routeCollection.MapRoute("CustomerActivityUrlCreation",
"Customer/{id}",
new { controller = "CustomerActivity", action = "DisplayDetails" });
The only other thing I can think of doing is to radically differentiate the Urls and get rid of the constraint on CustomerActivity, but I'd prefer not to do this. Does anyone else have any other suggestions on how to resolve this?