【发布时间】:2016-12-18 21:15:00
【问题描述】:
将 routeTemplate 定义为“api/{controller}/{id}”并在我的控制器 (ValuesController) 中有以下方法
[HttpGet]
public IEnumerable<string> GetX()
{
return new string[] { "xx1", "xx2" };
}
[HttpGet]
public IEnumerable<string> GetY([FromUri]Customer c)
{
return new string[] { "c1", "c2" };
}
public class Customer
{
public bool IsMarried { get; set; }
public string CustName { get; set; }
}
使用 url - "/api/values?IsMarried=false&CustName=aa" 会导致错误 - "Multiple actions were found that match the request..." 。 如果不将 routeTemplate 更改为“api/{controller}/{action}/{id}”之类的内容,我无法解决上述问题。 如果有人知道如何在不更改 routeTemplate 的情况下解决上述问题,请建议。
【问题讨论】:
-
您可以使用
[Route("...")]指令仅为特定控制器定义不同的路径。 -
谢谢@TasosK。期待你的答复。看起来添加“Route”属性在我的特定情况下可能没有帮助,因为我正在使用的客户端由于某些原因只能调用 REST url(即不使用操作名称)。