I have an MVC 4
application. In that application I have certain Areas, whose URL is not resolved properly. The LocationAreaRegistration.cs
is as follows:
context.MapRoute(
"Location_default",
"{culture}/{controller}/{action}/{id}",
new { culture = "en", action = "LocationIndex", id = UrlParameter.Optional },
new { controller = "(LocationIndex)" }
);
My route.config
is as follows:
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");
I have also tried to change the route.config
as below:
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" }
);
None of the approaches worked and I get The resource cannot be found
error.
However when I change the LocationAreaRegistration.cs
as follows, it works:
context.MapRoute(
"Location_default",
"{culture}/Location/{controller}/{action}/{id}",
new { culture = "en", action = "LocationIndex", id = UrlParameter.Optional },
new { controller = "(LocationIndex)" }
);
But I do not want the URL to contain the Location
(Area name). What am I doing wrong?
EDIT
The URLs that I would be going to will be somewhat like:
http://localhost/en/LocationIndex/LocationIndex
Here en
is the current culture, Home
is the controller
name and Index
is the action method
name.