I am trying to upload a couple of files. The upload itself works well for a single upload but I can't figure out how to access the element name to make sure each upload is assigned to the correct field. HttpPostedFileBase doesn't seem to contain that type of info anymore.
public ActionResult Edit(int id, FormCollection collection) {
Report report = re.GetReport(id);
var fileNames = new List<string>();
foreach (string file in Request.Files) {
var postedFile = Request.Files[file] as HttpPostedFileBase;
if (postedFile.ContentLength == 0)
continue;
fileNames.Add(UploadFile(basedir, postedFile));
}
// Rather than guessing which is which I'd like to get the field name or id.
report.Image = fileNames[0];
report.File = fileNames[1];
UpdateModel(report, "report");
rep.Save();
In the view I have
<%: Html.LabelFor(model => model.report.Image)%>
<input id="report_Image" type="file" name="Image" />
<%: Html.LabelFor(model => model.report.File)%>
<input id="report_Image" type="file" name="File" />
Thanks, Duffy