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....
}
1
  • I will look at this post, when I find solution I delete this one. Thanks Commented Apr 30, 2015 at 9:01

2 Answers 2

0

Please try this one.

[HttpPost]
public ActionResult Upload(HttpContext context)
{
  for (int files = 0; files < context.Request.Files.Count; files++)
 {
 // Code here
 }
}
Sign up to request clarification or add additional context in comments.

Comments

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
 }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.