Reputation: 24488
How do I redirect to a Controller without defining the Action? (it will default to the default action as defined in the routes config)
Example
return RedirectToAction("Index", "Error" new { messageId = errorMessageId} );
Url displayed to user is: http:mydomain/Error/Index/1001
Preferred
return RedirectToAction(null, "Error" new { messageId = errorMessageId} );
URL I want to displayed to user is: http:mydomain/Error/1001
When I type the URL manually, it works fine, so I know my routes are working.
I just cant figure out how to do it using Redirectxxxx in MVC.
Upvotes: 0
Views: 1038
Reputation: 56849
You can use RedirectToRoute
.
return RedirectToRoute(new { controller = "Error", messageId = errorMessageId });
Alternatively, there is Redirect
coupled with Url.RouteUrl
.
return Redirect(Url.RouteUrl(new { controller = "Error", messageId = errorMessageId }));
Upvotes: 1