ApiController操作无法从查询字符串解析数组

Pla*_*mes 3 c# asp.net-mvc-4 asp.net-web-api

使用Visual Studio 2012.2,MVC4 Web应用程序.

我有这样的请求来到我的ApiController:

http://localhost/api/keys?ids[]=1&ids[]=2&ids[]=3
Run Code Online (Sandbox Code Playgroud)

我的印象是以下方法应该能够自动从ids []数组中检索值:

public KeysModel Get(int[] ids){...}
Run Code Online (Sandbox Code Playgroud)

但是,当出现上述请求时,"ids"参数的值为null.

我已经检查过HttpContext.Current.Request.QueryString有ids的值,我可以这样做,但这会使单元测试变得更难.

我也尝试使用List ids,[FromUri],[FromUri(Name ="ids []")],对象ID和字符串id(有趣的是......当ids是一个字符串变量时,其中的值是" (采集)"

Pla*_*mes 5

原来:

public KeysModel Get([FromUri]int[] ids){...}
Run Code Online (Sandbox Code Playgroud)

答案毕竟是答案.

不知道我之前在做什么......