【发布时间】:2014-02-10 20:02:41
【问题描述】:
(我正在使用 WebApi 4.0.20710.0,框架 4.0。我不确定这是否重要,但我们还没有被允许将服务器升级到 4.5)
我想做的是这样打电话:
http://domain/api/Books/Outstanding/2013-01-01/2014-01-01
在我的ApiController 中,我有一个类似这样的方法:
/// <summary>
/// Get a list of books that were outstanding between the start and end dates.
/// </summary>
public IEnumerable<BookDto> GetOutstanding(DateTime start, DateTime end)
{
return _repository.GetOutstanding(start, end);
}
在我的RouteConfig 中,我有一个这样定义的路线:
routes.MapRoute(
name: "ActionWithStartAndEnd",
url: "{controller}/{action}/{start}/{end}"
);
然而,这些都没有真正奏效。我最终得到一条错误消息,上面写着"No action was found on the controller 'Books' that matches the request."
我怀疑我做错了一些简单的事情,和/或对一般路由有误解。我该怎么做?
【问题讨论】:
-
但是您的操作名称是
GetOutstanding而不是OutStanding -
我不得不匿名化代码,可能很糟糕。坦率地说,默认值具有误导性。我会删除它们。
标签: c# asp.net-mvc-4 asp.net-web-api asp.net-mvc-routing