In my angular application, I am getting an error when invoking an API method from angular. I have to pass two parameters. First one an integer value and second one string value. it is optional.
Please see the below code snippet (Typescript)
let id:number = 5;
let value: string = "";
this.http.get<string[]>(this.appService.baseUrl + 'api/File/' + id + "/" + value)
In Controller:
[HttpGet("{id:int}/value")]
[ResponseCache(NoStore = true)]
public async Task<IActionResult> Get(int id, string value) { }
Here the Get method is not invoking since the value parameter is empty.
In your example, you're building this URL:
/api/File/5
However, your controller expects the following:
/api/File/5/value
If you want value
here to be optional and to be placed into the value
parameter (string value
), you can adjust your HttpGet
attribute, like this:
[HttpGet("{id:int}/{value?}")]
This makes value
optional and is a placeholder for whatever gets passed in.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With