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.

2

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.