0

I'm trying to send data from a JavaScript Fetch to a .Net controller.
But I'm having quite a lot of troubles.
I'm currently trying something like so:

let response = await fetch("/MyRoute", {
  method: "POST",
  headers: { "Content-Type": "application/json; charset=utf-8" },
  body: {
    model: JSON.stringify(this.myModel),
    image: JSON.stringify(this.myModel.image),
  },
});

And I'm trying to retrieve it from my controller like so

public async Task<IActionResult> MyRoute([FromBody]Menu model, [FromBody]IFormFile image)
{
}

And Nothing more if I try:

public async Task<IActionResult> MyRoute([FromBody]Menu model, [FromBody]dynamic image)
{
}

Both model and image are empty.
I managed to have model filled in by removing second frombody but it's not helping me much:

public async Task<IActionResult> MyRoute([FromBody]Menu model, IFormFile image)
{
}

I stumbled upon this answer suggesting that sending 2 objects in body of different kind can be quite tricky. But I can't figure out how to adapt it to my JS-only to .Net case.

Platypus
  • 321
  • 1
  • 4
  • 17

0 Answers0