所以我有以下的控制:如何使用URL將參數設置爲FromURI?
public class ItemQuery {
public int storeID { get; set; }
public int companyID { get; set; }
public string itemName { get; set; }
public string itemDescription { get; set; }
public string itemPLU { get; set; }
public string itemUPC { get; set; }
public int supplierID { get; set; }
public string partNumber { get; set; }
}
public class ItemController : ApiController {
public List<Item> FindItem([FromUri]ItemQuery query) {
return new List<Item>();
}
}
我想這個要求打:
http://localhost:43751/api/Item/Find?query[storeID]=1
而且這不是工作,但給我這個錯誤:
The requested resource does not support http method 'GET'.
我該怎麼辦?這裏是我的路由信息,我並沒有改變任何東西:
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
剛剛嘗試過,效果非常好! – Bill