I have an action on my web project which calls to an API
[HttpPost]
public async Task ExpireSurvey(int id)
{
var token =
You can use anonymous types like this
var x = new { id = 2, date = DateTime.Now };
var data = JsonConvert.SerializeObject(x);
When receiving the data, you can only have one [FromBody] parameter. So that doesn't work for receiving multiple parameters (unless you can put all but one into the URL). If you don't want to declare a DTO, you can use a dynamic object like this:
[HttpPost]
public void Post([FromBody] dynamic data)
{
Console.WriteLine(data.id);
Console.WriteLine(data.date);
}
Don't overdo using anonymous types and dynamic variables though. They're very convenient for working with JSON, but you lose all type checking which is one of the things that makes C# really nice to work with.