【发布时间】:2018-09-05 17:15:35
【问题描述】:
我想通过这个 URI 路由我的 API
localhost/api/ServiceA/1234
其中 isbn=1234
目前我正在从下面提到的 UrI 中检索 json
localhost/1234
其中 1234 是 isbn
如何使用以下 uri 获得相同的 json 结果?
localhost/api/ServiceA/1234
目前我在上面的 URL 中得到了 null
通过使用属性路由的以下代码,我得到了结果
我有一个 API 计数器
public class ServiceAController : ApiController
{
[Route("api/ServiceA/{isbn}")]
public Book GetBook(string isbn)
{
using (AppDbContext db = new AppDbContext())
{
var query = from b in db.Books
where b.ISBN == isbn && b.Source == "Book Store 1"
select b;
return query.SingleOrDefault();
}
}
}
【问题讨论】:
标签: c# asp.net asp.net-web-api2