在控制器端点的路由上定义可选参数的正确语法是什么?
[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 :(得分: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)