New to .NET Core.
What am I doing wrong? Here is my controller
[Route("api/[controller]")]
public class customerController : Controller
{
// GET: api/values
//[HttpGet]
//public IEnumerable<string> Get()
//{
// return new string[] { "value1", "value2" };
//}
// GET api/values/5
[HttpGet("{id}")]
public customer Get(int id)
{
var repo = new customerRepository();
return repo.GetCustomerOnPhone(id);
}
}
I am able to call the API with this URL
http://localhost:51375/api/customer/8172858817
I hit the breakpoint in GET method, but Id is always zero. I cannot get the method to read the value which is being passed from URL.
Any suggestions?
int MaxValue = 2147483647
Your value 8172858817
is too large.
Either use a smaller value or change parameter to long
[HttpGet("{id:long}")]
public IActionResult Get(long id) {
var repo = new customerRepository();
customer model = repo.GetCustomerOnPhone(id);
return Ok(model);
}
Reference Routing in ASP.NET Core : Route Constraint Reference
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