Im using routes.add instead of routes.maproute (which has a namespace arg) because I extended the Route Class. I need to add namespace on the routes because one of my Areas has the same controller name within the site. My problem is I dont know where to put the namespace..
public class CultureRoute : Route
{
public CultureRoute(string url, object defaults, object constraints, RouteValueDictionary dataTokens)
: base(url, new RouteValueDictionary(constraints), dataTokens, new MvcRouteHandler())
{
}
}
Global.asax
routes.Add("Default", new CultureRoute(
"{controller}/{action}/{id}",
new {controller = "Home", action = "Index", id = UrlParameter.Optional}));
In its simplest form, a Namespace Routing Language (NRL) schema consists of a mapping from namespace URIs to schema URIs. An NRL schema is written in XML. DSDL Part 4 (ISO/IEC 19757-4), NVDL is based on NRL.
Multiple Routes You need to provide at least two parameters in MapRoute, route name, and URL pattern. The Defaults parameter is optional. You can register multiple custom routes with different names.
A custom route constraint can also be used with a Convention based routing. The new version MVC has an override version MapRoute method that accepts a constraint as a parameter. Using this method we can pass over a custom constraint.
var dataTokens = new RouteValueDictionary();
var ns = new string[] {"MyProject.Controllers"};
dataTokens["Namespaces"] = ns;
routes.Add("Default", new CultureRoute(
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = UrlParameter.Optional },
null /*constraints*/,
dataTokens
));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With