Search code examples
asp.net-mvcmultiple-file-upload

Upload multiple files to MVC controller


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?


Solution

  • try this-

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