0

I am able to get the route using this attribute -

[Route("api/[controller]?{n}")]
        [HttpGet("{n}")]

I have tried this but I had no luck.

  [HttpGet]
        public string Get([FromQuery(Name = "n")] long n)

However, my REST request is like -

http://<>/api/test?n=23

My API works with the REST API -

http://<>/api/test/23

I have tried changing the / with ? but no luck.

Prawn Hongs
  • 441
  • 1
  • 5
  • 17
  • See [this answer](https://stackoverflow.com/a/50468541/2309376) – Simply Ged Jan 23 '19 at 02:18
  • 1
    Possible duplicate of [How to read values from the querystring with ASP.NET Core?](https://stackoverflow.com/questions/41577376/how-to-read-values-from-the-querystring-with-asp-net-core) – Simply Ged Jan 23 '19 at 02:19
  • With `[Route("api/[controller]")]` on controller level, it should work with `[HttpGet]` and `public string Get([FromQuery] long n)` on action. – Ryan Jan 23 '19 at 05:46

1 Answers1

0

If you haven't found the solution yet please see below.

On your controller [Route("api/[controller]/[action]")]

[Route("api/[controller]/[action]")]
public class TestController: Controller
{
    [HttpGet]
    public IActionResult GetSomething([FromQuery]int id)
    {
      return Ok(id);
    }
}

This will yield the following route - http://localhost:5200/api/test/GetSomething?id=25

cl0ud
  • 1,524
  • 11
  • 27