I am tasked with upgrading a large Framework ASP.NET MVC application to .NET 5. Most of the work is done, but I'm running into an issue with HTTP POST calls from the frontend with JSON objects.
Most of these POST calls have a JSON body like this:
{
"param1" : "hello",
"param2" : "world",
"param3" : 123
}
Its corresponding controller action would look like this:
public ActionResult SaveData(string param1, string param2, int param3)
{
//Do save stuff
}
This doesn't work in ASP.NET Core. The parameters stay empty. I did find one solution, which is to encapsulate these parameters in a model object and use that as the only parameter with a [FromBody] attribute. However, this application has hundreds of actions with all kinds of parameters and I'm really not looking forward to having to write models for all of these.
So, I'm looking for a way to tell ASP.NET to treat the properties of these JSON objects as parameters for the corresponding action. I've googled around a bit, but couldn't find anything useful. Is there any way to do this, or am I stuck with having to write models for every single action?