【发布时间】:2017-01-26 21:09:52
【问题描述】:
我有一个 API 操作:
[HttpGet, Route("{id}/overview/")]
public async Task<HttpResponseMessage> Overview(string id, DateTime from, DateTime? to)
{
...
}
如您所见,to 是可选参数,但是当我提出请求时:
'/api/cream/3d7dd454c00b/overview?from=2016-09-04T18:00:00.000Z
我收到 404 错误。如果我从参数中删除to:
public async Task<HttpResponseMessage> Overview(string id, DateTime from)
然后一切正常。如何强制它使用to 参数?
【问题讨论】:
-
在您的示例中,
to不是可选的。您需要将其更改为optional argument。即Overview(string id, DateTime from, DateTime? to = null)。就是这样。
标签: c# asp.net-web-api asp.net-web-api-routing attributerouting