Some classes
public class FileUpload
{
public int ID { get; set; }
public string Filename { get; set; }
}
public class UploadModel
{
public List<FileUpload> Files { get; set; }
}
The view
@model UploadModel
@if (Model.Files.Any())
{
<table>
@foreach (FileUpload file in Model.Files)
{
<tr>
<td>@file.ID</td>
<td>@file.Filename</td>
</tr>
}
</table>
}
@using (Html.BeginForm("Upload", "Home"))
{
for(int i = 0; i < Model.Files.Count; i++)
{
@Html.HiddenFor(m => m.Files[i].ID)
@Html.HiddenFor(m => m.Files[i].Filename)
}
<span>Filename:</span><input type="text" name="filename"/>
<input type="submit" value="Upload"/>
}
Controller
[HttpGet]
public ActionResult Index()
{
UploadModel model = new UploadModel();
model.Files = new List<FileUpload>();
return View(model);
}
static int NextID = 1;
[HttpPost]
public ActionResult Upload(UploadModel model, string filename)
{
if (model.Files == null)
{
model.Files = new List<FileUpload>();
}
FileUpload file = new FileUpload();
file.Filename = filename;
file.ID = NextID++;
model.Files.Add(file);
return View("Index", model);
}