这是我在控制器中的代码
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
string TempPath = Server.MapPath("~/TempImages/");
foreach (HttpPostedFileBase file in files)
{
string filePath = Path.Combine(TempPath, file.FileName);
Tempdata["paths"] =filePath;
}
}
如何每次插入路径并将其作为数组/ arraylist进行插入?
更新: 对于每个已经运行的行为正在运行的图像,这是真正发生的事情
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
if (!Directory.Exists(Server.MapPath("~/TempImages/")) || files !=null)
{
string TempPath = Server.MapPath("~/TempImages/");
List<string> paths = new List< String> ();
foreach (HttpPostedFileBase file in files)
{
string filePath = Path.Combine(TempPath, file.FileName);
System.IO.File.WriteAllBytes(filePath, ReadData(file.InputStream));
file.SaveAs(filePath);
paths.Add(filePath);
TempData["paths"] = paths;
}
}
return view();
}
答案 0 :(得分:1)
你能做到吗
public ActionResult UploadFiles(IEnumerable<HttpPostedFileBase> files)
{
List<string> paths = new List<string>();
foreach (HttpPostedFileBase file in files)
{
string filePath = Path.Combine(TempPath, file.FileName);
paths.Add (filePath);
}
Tempdata["paths"] = paths;
}