【发布时间】:2014-05-06 03:29:53
【问题描述】:
如何使这条路线有效:
routes.MapRoute(
name: "Custom",
url: "{modality}/{controller}/{action}/{id}",
defaults: new {controller = "Home", action = "Index", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
如果需要,我需要打电话:
/ModalityName/SomeController/SomeAction/SomeId
或
/SomeController/SomeAction/SomeId
但是来自 mvc 的默认第二条路由不起作用。
我只需要一些时间来通知该模态,以便我可以根据该模态获取一些内容
【问题讨论】:
-
我认为这是因为您将“modality”设置为可选,没有设置其默认值。因此,当您调用
/SomeController/SomeAction/SomeId时,它默认为第二条路线,即“默认”。 -
而且,如果您将其设为可选并设置其默认值,则第二条路由将永远不会被评估,因为第一条路由将始终与 url 模式匹配。因此,用户必须输入 url 模式,这样它就不会默认为第二条路由。
标签: c# asp.net-mvc asp.net-mvc-routing