Arunudoy Buragohain
Arunudoy Buragohain

Reputation: 31

Accept any JSON data into .NET Core Web API controller (No Model)

I want an angular application to send any JSON data to a .Net Core WebAPI controller.

I don't want to have a pre-defined model accepting the JSON in the controller function.

I don't know how to accept it. Kindly help. In Angular, the data is JSON.stringified and POSTED

Here is my angular TS code that sends the JSON:

 Here is my angular TS code that sends the JSON (this.data, fetched from angular JSON Editor)

Controller that can accept any form of JSON:

Controller that can accept any form of JSON ?

Upvotes: 1

Views: 2852

Answers (1)

Rosco
Rosco

Reputation: 2474

As long as the client is posting JSON, you can define a string parameter that will accept any format JSON data.

For example:

[HttpPost]
public async Task<IActionResult> UploadJson([FromBody] string json)
{
    return Ok();
}

Upvotes: 1

Related Questions