【发布时间】:2020-07-01 02:15:23
【问题描述】:
这很可能是重复的,但我已经看过但找不到答案。这里的第一个答案看起来很有希望:Query string not working while using attribute routing 但我试过了,但没有用。
[HttpGet, Route("api/machine/byid/{id=id}/{pageNumber=pageNumber}/{pageSize=pageSize}/{fields=fields}")]
public string ById(int id, int pageNumber, int pageSize, string fields)
// code removed
}
这行得通:
https://localhost:44303/api/machine/byid/1/2/3/a,b,c
这不是:
https://localhost:44303/api/machine/byid?id=1&pageNumber=2&pageSize=3&fields=a,b,c
第二个url返回:
{"type":"https://www.rfc-editor.org/rfc/rfc7231#section-6.5.1","title":"出现一个或多个验证错误。","status": 400,"traceId":"|bf12950b-472923d3a24062d1.","errors":{"id":["值 'id' 无效。"],"pageSize":["值 'pageSize' 无效有效。"],"pageNumber":["值'pageNumber'无效。"]}}
【问题讨论】:
标签: asp.net-core routing