1

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 ?

1
  • If you stringified your data in Angular which means your backend must take a string from body. so you can write [FromBody] string body . Otherwise you need to use StreamReaderbut I am not sure is it ethic or not. May be you can write different methods for them. Commented Jun 20, 2020 at 22:03

1 Answer 1

1

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();
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.