【发布时间】:2012-11-08 14:33:26
【问题描述】:
我正在使用 Web API,我是新手。我陷入了路由问题。我有一个具有以下操作的控制器:
// GET api/Ceremony
public IEnumerable<Ceremony> GetCeremonies()
{
return db.Ceremonies.AsEnumerable();
}
// GET api/Ceremony/5
public Ceremony GetCeremony(int id)
{
Ceremony ceremony = db.Ceremonies.Find(id);
return ceremony;
}
public IEnumerable<Ceremony> GetFilteredCeremonies(Search filter)
{
return filter.Ceremonies();
}
当我将操作 GetFilteredCeremonies 添加到我的控制器时,问题发生了。添加此内容后,当我对 GetCeremonies 操作进行 ajax 调用时,它会返回带有以下消息的异常:
"Message":"An error has occurred.","ExceptionMessage":"Multiple actions were
found that match the request
仅供参考:参数Search 是模型类,其中包含属性和函数名称仪式。
编辑
路线:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
【问题讨论】:
-
你也可以分享你的路线吗?
-
@alliswell 请检查我的编辑
-
我认为这和stackoverflow.com/questions/9499794/…是同一个问题
-
在控制器中有两个名为 GetCeremony() 的方法尝试解决它们,因为它们都指向相同的路由
标签: c# asp.net-web-api