请参阅MVC的这个链接:http://aspnetwebstack.codeplex.com/discussions/351011
我遇到模型绑定问题.从JavaScript我执行GET Ajax请求到我的API端点"/ api/products",传递一些参数,包括分页和排序作为查询参数.这是完整的URI:
http://localhost/api/products?page=1&count=10&filter[name]=Test1&filter[price]=10&sorting[name]=desc
Run Code Online (Sandbox Code Playgroud)
在服务器端,我有一个Web API控制器从URI接受这些属性:
public async IHttpActionResult Get([FromUri]Dictionary<string,string> filter, [FromUri]Dictionary<string,string> sorting, int count, int page)
{
//...
}
Run Code Online (Sandbox Code Playgroud)
"count"和"page"参数绑定完全正常,过滤器和排序绑定为字典的实例,但其计数为0.
我在MVC中使用了它,但它似乎没有在Web API中使用卡车.