我使用 RedirectToRoute 方法来强制 url 中的区域性。一切正常,直到我在项目中创建管理区域。现在该方法重定向到区域 Controller 。
主 HomeController 示例:/Home/Contact
public ActionResult Contact()
{
Response.RedirectToRoute(RouteData.Values);
return View();
}
该方法重定向到/Admin/Home/Contact,重定向前RouteData.Values的值为:
[0] "Controller" Home
[1] " Action" Contact
我的主要路线:
routes.MapRoute("Default_culture", "{culture}/{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional , new { culture = "([a-z]{2,3})(-[a-zA-Z]{2})?" }, new[] { "Project.Controllers" });
routes.MapRoute("Default", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "Project.Controllers" });
RegisterArea 方法中的路由:
context.MapRoute(null, "{culture}/Admin/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new { culture = "([a-z]{2,3})(-[a-zA-Z]{2})?" }, new[] { "Project.Areas.Admin.Controllers" });
context.MapRoute(null, "Admin/{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = UrlParameter.Optional }, new[] { "Project.Areas.Admin.Controllers" });
我不明白这种行为。我做错了什么?
最佳答案
我刚刚在我的网站上解决了这个问题。
更改Response.RedirectToRoute(RouteData.Values);
至 Response.RedirectToRoute("默认", RouteData.Values);
关于asp.net-mvc - MVC Response.RedirectToRoute(RouteData.Values) 重定向到区域 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23711956/