【发布时间】:2018-06-15 10:40:26
【问题描述】:
是否可以根据输入的多个 id 创建一个 GET 操作?
例如,我怎样才能将此方法更改为 GetCustomer([FromRoute] int id, int code_id)?
// GET: api/Customer/5
[HttpGet("{id}")]
public async Task<IActionResult> GetCustomer([FromRoute] int id)
{
if (!ModelState.IsValid)
{
return BadRequest(ModelState);
}
var customerMaster = await _context.CustomerMaster.SingleOrDefaultAsync(m => m.Code == id);
if (customerMaster == null)
{
return NotFound();
}
return Ok(customerMaster);
}
【问题讨论】:
-
是的,一个方法可以有多个参数。额外的 GET 参数要么在路由中,要么在查询字符串中。
-
我只是想知道我对 -1 的问题有什么问题?