public ActionResult ImportExcel() { if (Request.Files.Count == 0) { return(Json( new OperateResult { content = "请上传数据文件", }, JsonRequestBehavior.AllowGet )); } HttpPostedFileBase file = Request.Files["fileName"]; if (file == null) { return(Json( new OperateResult { content = "请上传数据文件", }, JsonRequestBehavior.AllowGet )); } switch (Path.GetExtension(file.FileName)) { case ".xlsx": case ".xls": break; default: return(Json( new OperateResult { content = "上传的文件不是Excel文件", }, JsonRequestBehavior.AllowGet )); } string target = Server.MapPath("/") + ("/Upload/");//取得目标文件夹的路径 int pos = file.FileName.LastIndexOf('\\'); string filename; if (pos >= 0) { filename = file.FileName.Substring(pos + 1); } else { filename = file.FileName; } string path = target + filename;//获取存储的目标地址 file.SaveAs(path); OperateResult or = AssessmentManager.ImportExcel(path); return(Json(or, JsonRequestBehavior.AllowGet)); }