0

I have problem. I use html5 input type file where. But when I send selected files to controller, list of HttpPostedFileBase has good count but every file is the same. Example I select files:

  • 1.xml
  • 2.xml
  • 3.xml

List has count 3 and every of rows are 1.xml.

Code View form:
<form target="response" action="/test/Upload" method="post" enctype="multipart/form-data">
<input type="file" accept="text/xml" id="files" name="files[]" multiple="multiple"/><br/>

Controller:

 [HttpPost]
public ActionResult Upload(List<HttpPostedFileBase> files)
{
  Any code Here....
}
Ramzesso
  • 3
  • 2

2 Answers2

0

Please try this one.

[HttpPost]
public ActionResult Upload(HttpContext context)
{
  for (int files = 0; files < context.Request.Files.Count; files++)
 {
 // Code here
 }
}
Nimesh Gami
  • 361
  • 1
  • 2
  • 18
0

You don't need to write [] in name attribute you only have to give name no need of [].

<input type="file" accept="text/xml" id="files" name="files" multiple="multiple"/>

And in controller you can do this

[HttpPost]
public ActionResult Upload(HttpPostedFileBase[] files)
{
 foreach (HttpPostedFileBase file in files)
 {
  //Save file
 }
}
Mairaj Ahmad
  • 14,434
  • 2
  • 26
  • 40