1

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 Postman example

1 Answer 1

3

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);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.