You can't. The id
of an HTML element is never sent to the server when posting a form. As far as the name
attribute is concerned you may loop through the Request.Files collection. In ASP.NET MVC it more common to use action parameters. Example:
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files" id="file1" />
<input type="file" name="files" id="file2" />
<input type="file" name="files" id="file3" />
<input type="submit" value="Upload files" />
</form>
and your controller action:
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/App_Data"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
It's as simple as that.