1

I'm trying to create a WebApi action method with the following signature:

[System.Web.Http.HttpPost]
public object Execute([FromUri] string command, [FromUri] string method, [FromBody] IDictionary<string, JToken> arguments)

However, when I hit this method with requests, arguments never binds correctly (the two URI fields do). The ModelState shows a Json.NET parse error at the first character. I've tried request bodies that look like: id=50 and arguments={ "id": 50 }. How do I have to formulate my request to allow WebApi to correctly bind my parameters?

ChaseMedallion
  • 20,860
  • 17
  • 88
  • 152
  • 1
    Dictionaries consist of keyValuePairs, thus in the json world an array of objects, each having a Key and Value property, so IDictionary binding requries json something like `arguments=[{Key:"id",Value:50},{Key:"another",Value:100}]`. Might be off slightly, if you serialized a Dictionary as a JSON object you'd see what I mean. – AaronLS Mar 18 '13 at 21:03

1 Answers1

3

You don't need the "id=" or "arguments=" in the request body. You should be able to just send something that looks like this:

{"key1": 4, "key2": 50, "key3": {"member1": "value"}}

and have it work. The Dictionary would then contain key1: a JValue with value 4, key2: a JValue with value 50, key3: a JObject with a member1 member with value "value".

Youssef Moussaoui
  • 12,187
  • 2
  • 41
  • 37