我有一个超级简单的控制器,有两种方法:
public IActionResult Users(long id)
{
return Json(new { name = "Example User" });
}
public IActionResult Users()
{
return Json(new { list = new List<User>() });
}
一个选择所有用户,另一个返回所有用户。在 web api 2 中,我可以使用以下路线并且一切正常:
config.Routes.MapHttpRoute(
name: "Users",
routeTemplate: "v1/Users",
defaults: new { action = "Users", controller = "Users" },
constraints: null,
handler: new TokenValidationHandler() { InnerHandler = new HttpControllerDispatcher(config) }
);
我在 startup.cs 中设置了以下路由:
app.UseMvc(routes =>
{
routes.MapRoute(name: "User_Default", template: "v1/{controller=Users}/{action=Users}/{id?}");
});
然而,这给了我一个AmbiguousActionException: Multiple actions matched. The following actions matched route data and had all constraints satisfied
我究竟做错了什么?