asp.net-mvc - MVC Response.RedirectToRoute(RouteData.Values) 重定向到区域 Controller

标签 asp.net-mvc asp.net-mvc-4 asp.net-mvc-routing

我使用 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/

相关文章:

c# - 需要帮助在类中创建/使用集合(C#、ASP.Net、MVC)

asp.net-mvc - ASP.NET MVC。将 ViewModel 绑定(bind)到集合中的项目

c# - displayformatattribute 自定义格式化字符串

c# - CustomAuthorizeAttribute - HttpActionContext 而不是 AuthorizationContext

c# - 具有相同 routeTemplate 和版本约束的 WebApi 路由

sql - Orchard : one property value does not save in SQL Server 2012

c# - 将安全问题转移到数据访问层

asp.net-mvc-4 - 如何最好地从 Nuget 写入 BundleConfig

asp.net-mvc-routing - 如何检查给定路径是否存在路由(ASP.NET MVC)?

asp.net-mvc - MVC 5 中的 VirtualPathProvider