I have this route mapped:
routes.MapRoute(
"SingleUser", // Route name
"Users/{username}", // URL with parameters
new {area="", controller = "Users", action = "SingleUser"}, // Parameter defaults
);
Shouldn’t this code:
return RedirectToAction("Index", "Users", new {username = "someUser"});
redirect to this URL: localhost/Users/someUser?
It instead returns me to: localhost/Users?username=someUser
If you’ve defined a specialized route, then you should use
RedirectToRoute.What’s happening is that MVC is falling back to the default route (“{controller}/{action}”).
Use
RedirectToActionwhen you don’t have a specialized route defined.Same goes for generating links with
ActionLinkandRouteLink.