public class ViewDataUploadFilesResult
{
public string Name { get; set; }
public int Length { get; set; }
}
public class uploadtestController : Controller
{
public ActionResult Index()
{
var r = new List<ViewDataUploadFilesResult>();
foreach (string upItem in Request.Files)
{
HttpPostedFileBase postedFile = Request.Files[upItem] as HttpPostedFileBase;
if (postedFile.ContentLength == 0)
continue;
string savedName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, postedFile.FileName);
postedFile.SaveAs(savedName);
r.Add(new ViewDataUploadFilesResult() { Name = savedName, Length = postedFile.ContentLength });
}
this.ViewData["upInfo"] = AppDomain.CurrentDomain.BaseDirectory.ToString();
return View("Index",r);
}
}
<%foreach (ViewDataUploadFilesResult v in this.ViewData.Model) { %>
<%= String.Format("<li>Uploaded: {0} totalling {1} bytes.</li>",v.Name,v.Length) %>
<%} %>