2020年12月31日星期四

In asp.net API HttpGet{id} works but when I change the {id} to something else it dose not work

Im pretty new to ASP core webAPI. Hopefully you guys can give me a hand.

I have been successfully using HttpGet{id} - postman has been serving the correct information back. However, I want to be able use "partNumber" in the url.

below is the working id get method:

'''      [HttpGet("{id}")]       public async Task<ActionResult<Model>> GetModel(int id)          {          return await _context.Models.FindAsync(id);          }  '''  

Here is the actual parameters that I would like to search on:

```    [HttpGet("{PartNumber}")]          public async Task<ActionResult<Model>> GetModel(int partNumber)          {            return await _context.Models.FindAsync(partNumber);          }            ```  

Postman returns 404 not found in the latter when I should see data returned.

Any help would be greatly appreciated. thanks

https://stackoverflow.com/questions/65526747/in-asp-net-api-httpgetid-works-but-when-i-change-the-id-to-something-else-it January 01, 2021 at 09:38AM

没有评论:

发表评论