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?

1 Answer 1

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

Something Like This

Sign up to request clarification or add additional context in comments.

2 Comments

Not work with me. I get the error "Unsupported Media Type".
Please look at this post. Apparently this guy is doing same thing as what you want to do. stackoverflow.com/questions/41367602/…

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.