mattruma
mattruma

Reputation: 16687

Dynamic model binding with ASP.NET WEB API

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.

Upvotes: 6

Views: 6114

Answers (1)

Matt Houser
Matt Houser

Reputation: 36103

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

Upvotes: 11

Related Questions