Reputation: 45
My issue is, when I try to pass a single string to my API I receive it as a null value in the API, but when I try to pass an integer to another controller it works fine, I guess it's a syntax issue. Bellow two controllers as example:
[HttpGet("amostra/get/id/{id}")]
public Amostra GetAmostraId(int id) => _amostra.GetById(id);
[HttpGet("amostra/get/cli/{nomeFantasia}")]
public Dictionary<int, Amostra> getByFantasia(string nF) => _amostra.GetByCliente(nF);
The first one works without an issue, the other one never works, later in the "GetByCliente(nF)" function I check the length of the string and then get the error: "System.NullReferenceException: 'Object reference not set to an instance of an object.'", "nF was null".
Postman example
Upvotes: 1
Views: 575
Reputation: 15015
Your variable name and your route must match.
Try this
[HttpGet("amostra/get/cli/{nf}")]
public Dictionary<int, Amostra> getByFantasia(string nF) => _amostra.GetByCliente(nF);
Upvotes: 3