2014-11-06 24 views
1

在控制器端點的路由上定義可選參數的正確語法是什麼?在路由中定義可選參數的Web.Api

[Route("customers/{customerId}/boats/{boatId}/bookings{contractId?}&{startDate?}&{endDate?}&{outOnly?}", Name = "GetBookingsByBoat")] 
    [ResponseType(typeof (IEnumerable<BookingSummaryDTO>))] 
    public IHttpActionResult Get(int customerId, int boatId, int? contractId, DateTime? startDate, DateTime? endDate, bool outOnly = false) 
    { 

上述編譯,但是當我嘗試並調用使用

customers/40/boats/24/bookings 

端點我得到:

{"message":"The requested resource does not support http method 'GET'."} 

千恩萬謝

回答

0

這是解決方案:

[Route("customers/{customerId}/boats/{boatId}/bookings", Name = "GetBookingsByBoat")] 
    [ResponseType(typeof (IEnumerable<BookingSummaryDTO>))] 
    public IHttpActionResult Get(int customerId, int boatId, int? contractId = null, DateTime? startDate = null, DateTime? endDate = null, bool outOnly = false)