带有简单 CRUD 控制器的 MVC 路由痛苦

问题描述 投票:0回答:1

我有两个控制器设置:

[Route("/My/Path/{id}/Parent")]
public class ControllerParent ... { ... }

[Route("/My/Path/{id}/Parent/{parentId}/Child")]
public class ControllerChild ... { ... }

...在运行时,此 URL 以某种方式转到

ControllerParent
,而不是预期的
ControllerChild

https://webhost/My/Path/{id}/Parent/{parentId}/Child/Delete/{key}

而这个进入正确的控制器,并且断点命中

ControllerChild
,正如预期的那样:

https://webhost/My/Path/{id}/Parent/{parentId}/Child/{key}
asp.net-mvc model-view-controller asp.net-mvc-routing
1个回答
0
投票

您是否尝试将

action
参数添加到如下所示的路线中?

[Route("/My/Path/{id}/Parent/{action}/{key?}")]
public class ControllerParent : Controller { ... }

[Route("/My/Path/{id}/Parent/{parentId}/Child/{action}/{key?}")]
public class ControllerChild : Controller { ... }
© www.soinside.com 2019 - 2024. All rights reserved.