【发布时间】:2018-05-08 22:12:44
【问题描述】:
.NET Core 的新手。
我做错了什么?这是我的控制器
[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);
}
}
我可以使用这个 URL 调用 API
http://localhost:51375/api/customer/8172858817
我在 GET 方法中打断点,但 Id 始终为零。我无法获得读取从 URL 传递的值的方法。
有什么建议吗?
【问题讨论】:
-
Max int is
2147483647你的值太大了。改为long -
或者使用Guid作为Id的
标签: c# asp.net-core asp.net-core-webapi