6

According to Scott Hanselman, on his blog, I should be able to do dynamic model binding and return a dynamic.

I have a Web API controller that contains a single method:

public dynamic Post(dynamic data)
{
     return data;
}

When I make the following call from Fiddler, I am getting a null returned.

POST http://localhost:57856/api/values HTTP/1.1
User-Agent: Fiddler
Host: localhost:57856
Content-Type: "application/json"
Content-Length: 22

{"Name": "jlucpicard"}

What am I missing here? Shouldn't it return JSON for data? This is a simpler follow-up to my original question ASP.NET WEB API not binding to dynamic object on POST.

Community
  • 1
  • 1
mattruma
  • 16,589
  • 32
  • 107
  • 171

1 Answers1

11

Your action is returning null because your "data" parameter is not being bound to the incoming json data.

Remove the quotes from "application/json" in your Content-Type header to bind to the data.

Content-Type: application/json
Matt Houser
  • 33,983
  • 6
  • 70
  • 88