[英].Net Core Web API
.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傳遞的值。
有什么建議?
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);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.