【发布时间】:2016-08-02 19:53:43
【问题描述】:
所以我正在使用Postman 测试我的一些路由,但我似乎无法让这个电话通过:
API函数
[RoutePrefix("api/Employees")]
public class CallsController : ApiController
{
[HttpGet]
[Route("{id:int?}/Calls/{callId:int?}")]
public async Task<ApiResponse<object>> GetCall(int? id = null, int? callId = null)
{
var testRetrieve = id;
var testRetrieve2 = callId;
throw new NotImplementedException();
}
}
邮递员请求
http://localhost:61941/api/Employees/Calls 不起作用
错误:
{
"Message": "No HTTP resource was found that matches the request URI 'http://localhost:61941/api/Employees/Calls'.",
"MessageDetail": "No action was found on the controller 'Employees' that matches the request."
}
http://localhost:61941/api/Employees/1/Calls 工作
http://localhost:61941/api/Employees/1/Calls/1 工作
知道为什么我不能在前缀和自定义路由之间使用可选项吗?我尝试将它们组合成一个自定义路由,这并没有改变任何东西,任何时候我尝试删除 id 都会导致问题。
【问题讨论】:
标签: c# asp.net asp.net-web-api asp.net-mvc-routing