RouteTable.Routes.GetVirtualPath with route data asp.net MVC 2
Posted
by Bill
on Stack Overflow
See other posts from Stack Overflow
or by Bill
Published on 2010-04-24T00:25:34Z
Indexed on
2010/04/24
0:33 UTC
Read the original article
Hit count: 1222
c#
|asp.net-mvc-routing
Dear all,
I'm trying to get a URL from my routes table. Here is the method.
private static void RedirectToRoute(ActionExecutingContext context, string param)
{
var actionName = context.ActionDescriptor.ActionName;
var controllerName = context.ActionDescriptor.ControllerDescriptor.ControllerName;
var rc = new RequestContext(context.HttpContext, context.RouteData);
string url = RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { actionName = actionName, controller = controllerName, parameter = param })).VirtualPath;
context.HttpContext.Response.Redirect(url, true);
}
I'm trying to map it to. However RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { actionName = actionName, controller = controllerName, parameter = param })) keeps giving me null. Any thoughts?
routes.MapRoute(
"default3", // Route name
"{parameter}/{controller}/{action}", // URL with parameters
new { parameter= "parameterValue", controller = "Home", action = "Index" }
);
I know I can use redirectToAction and other methods, but I would like to change the URL in the browser with new routedata.
© Stack Overflow or respective owner