請參閱從MVC此鏈接:http://aspnetwebstack.codeplex.com/discussions/351011模型的ASP.NET Web API的URI結合詞典
我有模型綁定的麻煩。從JavaScript我做一個GET Ajax請求到我的API端點叫做「/ api/products」,傳遞一些參數,包括分頁和排序作爲查詢參數。下面是完整的URI:
http://localhost/api/products?page=1&count=10&filter[name]=Test1&filter[price]=10&sorting[name]=desc
在服務器端,我有一個網頁API控制器從URI接受這些屬性:
public async IHttpActionResult Get([FromUri]Dictionary<string,string> filter, [FromUri]Dictionary<string,string> sorting, int count, int page)
{
//...
}
「計數」和「頁」參數綁定完全正常,過濾器和排序綁定爲字典的一個實例,但其計數爲0.
我在MVC中工作,但它似乎沒有在Web API中做卡車。
檢查提出的解決方案http://stackoverflow.com/questions/11950351/method-with-dictionary-parameter-in-asp-net-web-api – Veverke