Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 获取在.NET中输入多个ID的操作_C#_.net_Get - Fatal编程技术网

C# 获取在.NET中输入多个ID的操作

C# 获取在.NET中输入多个ID的操作,c#,.net,get,C#,.net,Get,可以根据输入的多个id创建一个GET操作吗 例如,如何将此方法更改为GetCustomer([FromRoute]int-id,int-code\u-id)? // GET: api/Customer/5 [HttpGet("{id}")] public async Task<IActionResult> GetCustomer([FromRoute] int id) { if (!ModelState.IsValid) { retu

可以根据输入的多个id创建一个GET操作吗

例如,如何将此方法更改为GetCustomer([FromRoute]int-id,int-code\u-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:api/Customer/5
[HttpGet(“{id}”)]
公共异步任务GetCustomer([FromRoute]int id)
{
如果(!ModelState.IsValid)
{
返回请求(ModelState);
}
var customerMaster=wait _context.customerMaster.SingleOrDefaultAsync(m=>m.Code==id);
如果(customerMaster==null)
{
返回NotFound();
}
返回Ok(customerMaster);
}
使用属性计算:

// GET: api/Customer/5/3

[Route("api/Customer/{id}/{code_id}")]
public async Task<IActionResult> GetCustomer(int id, int code_id)
{

        ...
   return Ok(customer);
}
//GET:api/Customer/5/3
[路由(“api/Customer/{id}/{code_id}”)]
公共异步任务GetCustomer(int-id,int-code\u-id)
{
...
返回Ok(客户);
}
使用属性计算:

// GET: api/Customer/5/3

[Route("api/Customer/{id}/{code_id}")]
public async Task<IActionResult> GetCustomer(int id, int code_id)
{

        ...
   return Ok(customer);
}
//GET:api/Customer/5/3
[路由(“api/Customer/{id}/{code_id}”)]
公共异步任务GetCustomer(int-id,int-code\u-id)
{
...
返回Ok(客户);
}

是的,一个方法可能有多个参数。额外的GET参数要么在路由中,要么在查询字符串中。我只是想知道-1的问题出了什么问题?是的,一个方法可能有多个参数。额外的GET参数要么在路由中,要么在查询字符串中。我只是想知道-1的问题中有什么错误?我如何在这里连接它们:(m=>m.Code==id)?通过一个简单的&?是的,您可以使用&,即(m=>m.Code==Code\u id&&m.id==id),如果我不想只返回我的第一个,即/1/2,我想返回所有具有/1/2的值,我应该怎么做?使用.ToList()和返回列表,而不是单个对象,即list customers=context.customers.Where(m=>m.Code==Code\u id&&m.id==id).toList();我如何在这里连接它们:(m=>m.Code==id)?通过一个简单的&&?是的,你可以使用&,即(m=>m.Code==Code\u id&&m.id==id),如果我不想只返回第一个值,即/1/2,我想返回所有具有/1/2的值,我该怎么做?使用.toList()和返回列表,而不是单个对象,即
list customers=context.customers.Where(m=>m.code==code\u id&&m.id==id.toList();