为什么第二条路线被跳过?第一个路由具有第二个路由的基本控制器类,因此小部件继承事件,但我的事件“注册”方法不断被击中。
网址
Widgets/v1/RegistrationWidget?eventid=3762
路线
routes.MapRouteLowercase(
"DefaultWidget",
"widgets/v{version}/{action}widget",
new { controller = "Widgets", action = "NotFound", version = 1, slug="event" },
new { version = @"\d+" }
);
routes.MapRouteLowercase(
"NamedEvent",
"{Id}/{slug}/{action}",
new { controller = "Event", action = "Index", slug = "event" },
new { Id = @"\d+" }
);
窗口小部件控制器
public partial class WidgetsController : EventController
{
public virtual ActionResult RegistrationWidget(int version, int? eventId, string slug, int? divisionTeamId = null, int? divisionId = null)
{
return GetRegistration(eventId, divisionId, divisionTeamId, new WidgetRegistrationViewModel(version));
}
事件控制器
public partial class EventController : SiteController
{
public virtual ActionResult Registration(int? id, string slug, int? divisionTeamId = null, int? divisionId = null)
{
return GetRegistration(id, divisionTeamId, divisionTeamId, new EventRegistrationViewModel());
}
答案 0 :(得分:3)
根据您的网址Widgets/v1/RegistrationWidget?eventid=3762
,操作名称将按照您的预期计算为Registration
,而不是RegistrationWidget
,因此mvc实际上使用第一条路线,但将其转发给基类方法。< / p>
答案 1 :(得分:0)
无论你在大括号之间放置什么,路由引擎将使用什么来尝试找到你正在寻找的动作,因为你要求RegistrationWidget并且你的路由被设置为{action}小部件,路由引擎将会看起来对于WidgetsController类中名为Registration的操作。这也让我感到很沮丧。