小编Cod*_*r77的帖子

.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);
    }
}
Run Code Online (Sandbox Code Playgroud)

我可以使用此URL调用API

http://localhost:51375/api/customer/8172858817

我在GET方法中遇到断点,但Id始终为零.我无法获取方法来读取从URL传递的值.

有什么建议?

c# asp.net-core asp.net-core-webapi

6
推荐指数
1
解决办法
110
查看次数

标签 统计

asp.net-core ×1

asp.net-core-webapi ×1

c# ×1