我有一个MVC 4
应用程序。在那个应用程序中,我有某些区域,其URL不能正确解析。该LocationAreaRegistration.cs
如下:设置路径到一个区域,但没有在MVC中的url中指定区域名称
context.MapRoute(
"Location_default",
"{culture}/{controller}/{action}/{id}",
new { culture = "en", action = "LocationIndex", id = UrlParameter.Optional },
new { controller = "(LocationIndex)" }
);
我route.config
如下:
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { culture = "en", controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Locator.Areas.Location.Controllers" }
).DataTokens.Add("area", "Location");
我也试图改变route.config
如下:
routes.MapRoute(
name: "Default",
url: "{culture}/{controller}/{action}/{id}",
defaults: new { culture = "en", controller = "Home", action = "Index", id = UrlParameter.Optional },
namespaces: new[] { "Locator.Areas.Location.Controllers" }
);
的方法都没有工作,我收到The resource cannot be found
错误。
然而,当我改变LocationAreaRegistration.cs
如下,它的工作原理:
context.MapRoute(
"Location_default",
"{culture}/Location/{controller}/{action}/{id}",
new { culture = "en", action = "LocationIndex", id = UrlParameter.Optional },
new { controller = "(LocationIndex)" }
);
但我不想要的网址包含了Location
(地区名)。我究竟做错了什么?
编辑
,我会去会有点像网址:
http://localhost/en/LocationIndex/LocationIndex
这里en
是当前的文化,Home
是controller
名称和Index
是action method
名。
好的一组MapRoutes,但不知道你要去的URL,这个问题是无法回答的。 –
@ErikPhilips:我编辑了我的问题。请检查 –
您的路由配置错误。请参阅[为什么要在asp.net mvc中的常用路由之前先映射特殊路由](http://stackoverflow.com/questions/35661062/why-map-special-routes-first-before-common-routes-in-asp-net -mvc/35674633)。 – NightOwl888