Associating a dynamic model with an ASP.NET API

According to Scott Hanselman, on a blog , I should be able to dynamically snap the model and return the dynamics.

I have a Web API that contains one method:

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

When I make the next call from Fiddler, I return null .

 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 implementation of my original ASP.NET WEB API question , not related to a dynamic object in POST .

+6
source share
1 answer

Your action returns null because your parameter "data" is not bound to incoming json data.

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

 Content-Type: application/json 
+11
source

Source: https://habr.com/ru/post/945950/


All Articles