I want to trigger the below route with this url:
http://localhost:66777/api/productdetails?articlegroup=1&producedat=2012-01-01
What is wrong with my - I guess - Route attribute?
[Route("api/productdetails/{articlegroup:int}/{producedat:datetime}")]
[HttpGet]
public async Task<IHttpActionResult> GetProductDetails([FromUri] ProductDetailsRequestDTO dto)
{
//...
}
public class ProductDetailsRequestDTO
{
public int ArticleGroup { get; set; }
public DateTime ProducedAt { get; set; }
}
Route templates support only the 'path' and not the query string. In your above example, you have articlegroup
and producedat
as route variables on the 'path' where as your are sending the data for these in the query string. Since the route template match fails to find this data in the path, you probably are getting a 404 - which is expected.