1

I'm using webapi asp.net core, initially my actions were using the [FromBody] attribute on the parameters, and my front end send a json. Now I'm implementing a screen that has upload, and I had to use FormData to send the file, and at that point I inserted my object (which I used to send as json) in my FormData. So, I needed to change my backend to accept the FormData, just remove [FromBody].

I would like use my action, both by passing formdata or passing a json, is it possible? How can implement this?

Ricardo Carvalho
  • 223
  • 5
  • 14

1 Answers1

1
YourController{
public IHttpActionResult YourMethod([FromBody] model1, [FromForm]model2)
{
//your model1 defines json model.
//model2  defines properties for file
}
}

Something Like This

Gurpreet
  • 1,382
  • 11
  • 24
  • Not work with me. I get the error "Unsupported Media Type". – Ricardo Carvalho Sep 05 '17 at 17:38
  • Please look at this post. Apparently this guy is doing same thing as what you want to do. https://stackoverflow.com/questions/41367602/upload-files-and-json-in-asp-net-core-web-api – Gurpreet Sep 06 '17 at 08:41