我有两个非常相似的 ASP.NET MVC 路由,如下所示。
有没有办法将这两条路由结合起来并放置一个条件语句,以便 (1) 对“logs/email/”的任何请求都会发送到 EmailLogsController,而对“logs/user/”的请求会发送到 UserLogsController?
// URL: /areax/logs/email/
// URL: /areax/logs/email/details/51
// URL: /areax/logs/email/details/117
context.MapRouteLowercase(
"AreaX.Log.Email",
"areax/logs/email/{action}/{id}",
new
{
controller = "EmailLogs",
action = "Index",
id = UrlParameter.Optional
},
new[] { ControllerNamespaces.AreaX }
);
// URL: /areax/logs/user/
// URL: /areax/logs/user/details/1
// URL: /areax/logs/user/details/10
context.MapRouteLowercase(
"AreaX.Log.User",
"areax/logs/user/{action}/{id}",
new
{
controller = "UserLogs",
action = "Index",
id = UrlParameter.Optional
},
new[] { ControllerNamespaces.AreaX }
);
就目前而言,它们看起来不是很干燥。