Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 771
mattruma Avatar asked May 27 '13 15:05

mattruma


1 Answers

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
like image 97
Matt Houser Avatar answered Oct 13 '22 14:10

Matt Houser