【发布时间】:2016-05-12 00:19:04
【问题描述】:
我有一个包含多种方法的 Web Api。我的路由有问题。我有一种方法是通过yearId 返回产品,另一种方法是通过product id 返回产品。这是我想出的两条路线:
/api/records/products?yearId=10
/api/records/products/15
这是我的两种方法:
[HttpGet]
[Route("getbyyearid")]
public async Task<Product> GetByYearid(int yearId)
{
.....
}
[HttpGet]
[Route("getbyid")]
public async Task<IEnumerable<Product>> GetByid(int productId)
{
......
}
我应该有什么路由映射,以便我可以使用这 2 条路由访问我的 Web API:
/api/records/products?yearId=10
/api/records/products/15
【问题讨论】:
标签: c# asp.net-web-api asp.net-web-api-routing