RouteTable.Routes.GetVirtualPath 与路由数据 asp.net MVC 2
我正在尝试从我的路由表中获取 URL。这是方法。
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);
}
我正在尝试将其映射到。然而 RouteTable.Routes.GetVirtualPath(rc, new RouteValueDictionary(new { actionName = actionName,controller =controllerName,parameter = param })) 不断给我 null 。有什么想法吗?
routes.MapRoute(
"default3", // Route name
"{parameter}/{controller}/{action}", // URL with parameters
new { parameter= "parameterValue", controller = "Home", action = "Index" }
);
我知道我可以使用redirectToAction 和其他方法,但我想使用新的路由数据更改浏览器中的URL。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
x 尝试 RouteCollection.GetVirtualPathForArea 相反,为我工作
x 路由和 GetVirtualPath 问题
实际上这不是任何问题不同的是,问题是路线值中的区域是空白的,我们仍然使用旧的 AreaViewEngine
作为临时修复,我们将空白区域更改为“根”,这样一切就可以正常工作
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