图片上传功能:
[HttpPost]
public String UploadSingle(HttpPostedFileBase imageFile)
{
try
{
String fileSavePath = Server.MapPath("~/Content/Temp/" +
imageFile.FileName);
imageFile.SaveAs(fileSavePath);
List<String> uploadedFile = (List<String>)HttpContext.Session["UploadedFiles"];
if (uploadedFile == null)
{
uploadedFile = new List<string>();
}
uploadedFile.Add(fileSavePath);
HttpContext.Session["UploadedFiles"] = uploadedFile;
return "Success";
}
catch (Exception e)
{
return "Error";
}
}
此功能正常,图片已上传。但是当我尝试查看上传的图像时。
public String UploadResult()
{
List<String> uploadedFile = (List<String>)HttpContext.Session["UploadedFiles"];
return uploadedFile.Count + "";
}
当我调试时, HttpContext.Session["UploadedFiles"] 总是返回 null。请给我一些帮助。