I am trying to figure out a way to send a Json formatted data to a web api controller in a neat(more natural) way.
let me explain. Suppose I have this controller:
[HttpPost]
public class StudentController : ApiController
{
public void PostSomething([FromBody] string name, [FromBody] Student s)
{
//do something
}
}
The json data that I WANT to post is something like this (as it is correctly formatted):
{
"name" : "John",
"student" : {
"id" : "1",
"age" : "22"
}
}
But what I SHOULD send for the web api to parameter bind
the objects should be like this:
{
"John",
{
"id" : "1",
"age" : "22"
}
}
The problem is that if I use my desired json format, both name
and student
objects will be null in the PostSomething
method of the controller.
How can I send a json request with a format similar to the first example to my web api controller?