ApiController操作无法从查询字符串解析数组
使用Visual Studio 2012.2,MVC4 Web应用程序。
我有这样的请求来到我的ApiController:
http://localhost/api/keys?ids[]=1&ids[]=2&ids[]=3
我的印象是以下方法应该能够自动从ids []数组中检索值:
public KeysModel Get(int[] ids){...}
但是,当出现上述请求时,“ids”参数的值为null。
我已经检查过HttpContext.Current.Request.QueryString有ids的值,我可以这样对待它们,但这会使unit testing变得更难。
我也尝试使用List ids,[FromUri],[FromUri(Name =“ids []”)],对象id和字符串id(有趣的是,当ids是一个字符串变量时,其中的值是“ (采集)”
原来:
public KeysModel Get([FromUri]int[] ids){...}
答案毕竟是答案。
不知道我之前在做什么……
- 发布的Azure Web角色中的CSS图标生成内容出现问题
- Azure:无法启动远程调试器
- 如何在自定义模型绑定器中validation我的模型?
- 获取一个完整的url,例如http://google.com作为操作输入
- 事件消息:发生了未处理的访问exception(IIS 7.5,无法加载网站)
- WebAPi – 统一来自ApiController和OAuthAuthorizationServerProvider的错误消息格式
- 即使将身份validation模式设置为“Windows”,ASP.Net MVC4 User.Identity.Name也会变为空
- MVC中的会话管理
- 在自托管WebApi中获取HttpRequest上下文