所以我測試我的一些路由出去與Postman
的,我似乎無法得到這個呼叫通過中間:網頁API可選參數與屬性路由
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 WORKS
http://localhost:61941/api/Employees/1/Calls/1 WORKS
任何想法,爲什麼我不能用我的前綴和自定義路線之間的可選?我已經嘗試將它們合併到一個自定義路由中,並且不會改變任何內容,任何時候我都會嘗試刪除導致問題的id。
雖然這可以作爲一個單獨的功能,我期待封裝所有3這些潛在的呼叫在1功能下,如果我理解可選路由權,它應該是可能的。 – tokyo0709