ASP.NET Core: [FromQuery] usage and URL format

The name of the method and return type are completely ignored when you define your route explicitly via attributes like that. IActionResult shouldn’t be there.

The correct URL would be: https://localhost:xxxxx/api/v1/ShelfID/{shelfID}/BookCollection?ID="123"&Name="HarryPotter"

Furthermore, query string binding only works out of the box for primitive types (string, int, etc). To bind a class to a query string you’d need a custom modelbinder, which is quite involved.

It would be better to just explicitly declare the properties you want to pass in:

public async Task<IActionResult> GetAllBooks(string shelfID,
                                             [FromQuery] string ID, 
                                             [FromQuery] string Name)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)