0
我有控制器,各種動作,其中之一是:多的行動中發現匹配的WebAPI請求
[HttpGet]
public IList<string> GetFoo(string id = null)
{ ... }
這個動作有個別路線:
routes.MapHttpRoute(
name: "GetFoos",
routeTemplate: "api/my/foo/{_id}",
defaults: new { controller = "My", action = "GetFoo" }
);
當我添加另一個動作:
[HttpGet]
public IList<string> GetBar()
{ ... }
請求到localhost/API /我/富/失敗:
Multiple actions were found that match the request:
↵System.Collections.Generic.IList`1[System.String] GetFoo(System.String) on type Controllers.MyController
↵System.Collections.Generic.IList`1[System.String] GetBar() on type Controllers.MyController"
有人可以解釋爲什麼會發生這種情況?我爲api/my/foo指定了action =「GetFoo」,爲什麼它與GetBar匹配?