【发布时间】:2016-11-24 23:16:55
【问题描述】:
我正在使用 ASP.NET Core MVC 创建一个网站。当我单击某个操作时,我收到此错误:
AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied:
Web.Controllers.ChangeEventsController.Create (Web)
Web.Controllers.ProductsController.CreateChangeEvent (Web)
这就是我在 index.cshtmlm 中为 ProductsController 定义操作的方式:
<a asp-controller="ChangeEvents" asp-action="Create" asp-route-id="@item.Id">Create Change Event</a>
这是我的路线:
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
这是我定义动作的方式:
// ChangeEventsController
[HttpGet("{id}")]
public IActionResult Create(Guid id)
// ProductsController
[HttpGet("{id}")]
public IActionResult CreateChangeEvent(Guid id)
我做错了什么?
更新
感谢@MegaTron 的回复,但是我想知道为什么我不能为不同的控制器提供相同的操作路径。如果我有许多控制器每个都创建实体,我觉得你提出的解决方案无法很好地扩展。
【问题讨论】:
-
你不需要 IShouldNotNeedThisIThink 路由声明。
-
我需要那条路线吗?
-
在最简单的情况下,您只需要默认的。
标签: c# asp.net-core asp.net-core-mvc asp.net-core-routing