是否可以返回上传到ajax的每个文件的路径,因为我需要显示刚刚在前端上传的图像。
public ActionResult Upload()
{
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/img"), fileName);
file.SaveAs(path);
}
return Json(new { Success = true, FilePath = "ssssss" });
}
答案 0 :(得分:0)
public ActionResult Upload()
{
//string[] lstfile = new string[];
List<string> lstfile = new List<string>();
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(Server.MapPath("~/Images/img"), fileName);
lstfile.Add("/Images/img/" + fileName);
file.SaveAs(path);
}
return Json(new { lstfile });
}