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.ActionNa开发者_如何学JAVAme;
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.
x try RouteCollection.GetVirtualPathForArea instead, worked for me
x Routing and GetVirtualPath problem
Actually this was not any different, the issue was that the area in the route values was blank and we are still using the old AreaViewEngine from way back
As a temp fix we change the area if blank to "root", and this then it all works fine
精彩评论