簡體   English   中英

.Net Core Web API

[英].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);
}

ASP.NET核心中的參考路由:路由約束參考

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM