【问题标题】:How multiple Get function could be there in a web api controllerWeb api控制器中如何有多个Get函数
【发布时间】:2016-08-04 15:40:16
【问题描述】:

只看场景

 public class CustomerController : ApiController
 {
     public IEnumerable<Customer> GetCustomersByID(int id)
     {

     }

     public IEnumerable<Customer> GetCustomersByName(string name)
     {

     }

     public IEnumerable<Customer> GetCustomersByEmail(string strEmail)
     {

     }
 }

现在告诉我我需要做什么,因此最终用户可以通过他们的名字调用三个 get 操作。如何处理这种情况。谢谢

【问题讨论】:

    标签: asp.net-web-api asp.net-mvc-routing


    【解决方案1】:

    您可以为每种方法设置路线。如:

     [Route("GetById/{id}")]
     public IEnumerable<Customer> GetCustomersByID(int id)
     {
    
     }
    

    你可以叫它getbyid/3。更多详情web api routing

    这个issue还有一个问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-24
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多