我正在使用 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
到我的控制器时,就会出现问题。添加此内容后,当我进行 ajax 调用GetCeremonies
操作时,它会返回带有以下消息的异常:
"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 }
);