0

如何传递超过10个参数查询字符串的一部分,我的asp.net网页API 2.如何查询字符串参数传递给asp.net网页API 2

这是我的asp.net网页API 2方法,我无法弄清楚,我怎么能装点这个方法,让它接受ID和一个复杂的类型,是CustomerRequest,我想使用网址类似

http://localhost/api/Customer/?Mobile0012565987&Email=abcxyz.com&IsEmailVerified=true

[ResponseType(typeof(Customer))] 
public IHttpActionResult GetCustomer(long id, [FromUri]CustomerRequest request) 
     { 
      var customer = db.Customers.Find(request.CustomerId); 

      if (customer == null) 
      { 
       return NotFound(); 
      } 

      return Ok(customer); 
     } 

这是

public class CustomerRequest 
    { 
     public string Mobile { get; set; } 
     public string Email { get; set; }   
     public Nullable<bool> IsEmailVerified { get; set; }  
    } 

否则pleaase指导我,如果有更好的方式来做到这一点CustomerRequest类。

感谢

+0

你能告诉你的路由表? –

回答

0

基于您的代码,你需要通过“ID”,以及像这样:

http://localhost/api/Customer/?id=12345&Mobile=0012565987&Email=abcxyz.com&IsEmailVerified=true

,如果你想“身份证”可选的,你可以让你的方法签名是这样的:

public IHttpActionResult GetCustomer([FromUri]CustomerRequest request, long id = 0) 

这将默认设置ID为0,如果你不通过它的URL。所以,你将能够访问您的网址就像你本来是:

http://localhost/api/Customer/?Mobile=0012565987&Email=abcxyz.com&IsEmailVerified=true

+0

谢谢阿里,它工作 – Shax

相关问题