Asp.net web api Api定义路由中的可选参数
在控制器端点的路由上定义可选参数的正确语法是什么Asp.net web api Api定义路由中的可选参数,asp.net-web-api,routes,optional,Asp.net Web Api,Routes,Optional,在控制器端点的路由上定义可选参数的正确语法是什么 [Route("customers/{customerId}/boats/{boatId}/bookings{contractId?}&{startDate?}&{endDate?}&{outOnly?}", Name = "GetBookingsByBoat")] [ResponseType(typeof (IEnumerable<BookingSummaryDTO>))] publi
[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)
{
我得到:
{"message":"The requested resource does not support http method 'GET'."}
非常感谢这是解决方案:
[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)
[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)