【发布时间】:2018-09-19 08:15:56
【问题描述】:
我正在尝试在我的 web api 中使用 [FromQuery],但我不知道如何使用它。
这是控制器中的 GetAllBooks() 方法:
[HttpGet]
[Route("api/v1/ShelfID/{shelfID}/BookCollection")]
public async Task<IActionResult> GetAllBooks(string shelfID, [FromQuery] Book bookinfo)
{
//do something
}
这是 Book 模型类:
public class Book
{
public string ID{ get; set; }
public string Name{ get; set; }
public string Author { get; set; }
public string PublishDate { get; set; }
}
我对这是否是使用 [FromQuery] 的正确方法感到困惑。我以为网址是
https://localhost:xxxxx/api/v1/ShelfID/{shelfID}/BookCollection/IActionResult?ID="123"&Name="HarryPotter"
但是断点没有击中我的控制器方法,所以我在想 URL 可能不正确。有什么建议?谢谢!
【问题讨论】:
标签: c# asp.net-core asp.net-core-webapi