既存のWebApiアクションがあり、HttpPostからHttpGetに切り替えたいと思います。現在、パラメータとして単一の複雑なオブジェクトを取ります。
モデル:
public class BarRequest
{
[JsonProperty("catid")]
public int CategoryId { get; set; }
}
コントローラー:
public class FooController : ApiController
{
//[HttpPost]
[HttpGet]
[ActionName("bar")]
public void Bar([FromUri] BarRequest request)
{
if (request != null)
{
// CategoryId should be 123, not 0
Debug.WriteLine("Category ID :: {0}", request.CategoryId);
}
}
}
次のリクエストを送信すると、すべてが期待どおりに機能します。
GET /foo/bar?CategoryId=123
また、古いPOSTリクエストは期待どおりに機能しました。
POST /foo/bar {"catid":123}
しかし今、私は次のリクエストが機能する必要があります:
GET /foo/bar?catid=123
どうすればこれを達成できますか?