3

I'm trying to upload multiple image to server. HTML-

<form action="" method="post" enctype="multipart/form-data">
    <input type="file" name="file" multiple /> 
    <input type="text" name="caption"/>
    <textarea name="description"></textarea>
    <input type="submit" value="Submit" />
</form>

I'm able to handle single file. Here is my code-

public ActionResult SubmitImage(FormCollection data)
{
     var file = Request.Files["file"];
}

How can I handle multiple files in server?

1
  • I think you need to change the id to files[] e.g. <input type="file" name="file[]" multiple /> Not 100% sure, thus I'm not posting this as an answer. Commented Jun 11, 2015 at 12:03

2 Answers 2

3

try this-

public ActionResult SubmitImage(IEnumerable<HttpPostedFileBase> file,FormCollection data)
{
     foreach (var f in file)
     {

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

1 Comment

Unfortunatly this does not work if someone uses the "upload" button in 2 steps.
0

I believe you are misunderstanding what Request.Files contains and how to access multiple files from the Request. Here is a link that has an appropriate example for you: http://www.mikesdotnetting.com/article/125/asp-net-mvc-uploading-and-downloading-files

Hope this helps.

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.