I want to add a custom route, but I can't get it to work. I want to use normal routing, except when it hits a specific controller,to use a different optional parameter instead of id.
In my area, this exists:
context.MapRoute(
"Admin_default",
"Admin/{controller}/{action}/{id}",
new { action = "Index", id = UrlParameter.Optional }
);
and above that I tried to add:
context.MapRoute(
"Admin_Users",
"Admin/Users/{action}/{username}",
new { action = "Index", username = UrlParameter.Optional }
);
And in code, I call the page with:
@Html.ActionLink("Edit", "Edit", new { username=user.UserName })
and it works, but the link shows up as /Admin/Users/Edit/?username
and I want: /Admin/Users/Edit/username
However, I want to keep the same route for all my other pages, that being:
/Admin/Shop/Products/Edit/1
which uses the default routing
EDIT
I got it to work by adding in controller="Users", in my route.
context.MapRoute(
"Admin_Users",
"Admin/Users/{action}/{username}",
new { controller="Users", action = "Index", username = UrlParameter.Optional }
);
I thought this was the point of the URL part (the line above) of it?