Here\'s the basic setup, I have an asp.net core webapi controller (in c#) with a post function like so:
[HttpPost]
public ActionResult Post([Fr
The serializable error is actually a parsing error from JSON.NET, but the problem actually has nothing to do with parsing JSON.
The real issue is that ASP.NET Core expects to parse a JSON body into an object/DTO. So you have two options you can use to fix the problem:
Make a simple DTO container object for your single parameter e.g.:
public class SimpleObject {
public string Name { get; set; }
}
Instead of passing a full fledged JSON object in your request body, just use a simple string e.g: "My parameter string"
You need a body in which json data will be parsed.
[FromBody] string Name
can not work with following json
{
"Name": "Foo"
}
It needs a class
public class MyClass
{
public string Name;
}
Then pass it as
([FromBody] MyClass obj)
Or if it is single value, use JSON like
{
[
"Foo",
"Foo1"
]
}
Then pass it as
([FromBody] List<string> obj)