Cod*_*r77 6 c# asp.net-core asp.net-core-webapi
.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);
}
}
Run Code Online (Sandbox Code Playgroud)
我可以使用此URL调用API
http://localhost:51375/api/customer/8172858817
我在GET方法中遇到断点,但Id始终为零.我无法获取方法来读取从URL传递的值.
有什么建议?
int MaxValue = 2147483647
你的价值8172858817太大了.
使用较小的值或更改参数 long
[HttpGet("{id:long}")]
public IActionResult Get(long id) {
var repo = new customerRepository();
customer model = repo.GetCustomerOnPhone(id);
return Ok(model);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
110 次 |
| 最近记录: |