Kyle
Kyle

Reputation: 33701

Get an uploaded file from a html form in MVC?

I have this file upload input in part of a pretty large form:

<input class="input-file" type="file" name="picture">

I am using:

public ActionResult Add(FormCollection form)

To get the rest of my form values, and it comes up with 'picture' in the FormCollection as well, but it only has the filename and not the actual picture. I have tried using this:

public ActionResult Add(FormCollection form, HttpPostedFile picture)

And this

Request.Files[0]

which are solutions I found on other SO questions, but both remain null.

I assume the file is actually getting posted since it shows up in the FormCollection.

How can I get this file? Trying to get it as a byte[] to save in database.

Thanks.

Upvotes: 2

Views: 4266

Answers (1)

Kyle
Kyle

Reputation: 33701

I was able to resolve this issue by changing the start of my form to:

@using (Html.BeginForm("Add","Recipe",FormMethod.Post, new { enctype = "multipart/form-data" }))

Upvotes: 2

Related Questions