【发布时间】:2015-12-16 12:20:52
【问题描述】:
这是我上传文件的控制器
控制器:
namespace MvcApplication5.Controllers
{
public class DataUploadController : Controller
{
public ActionResult Index()
{
return View("Index");
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Import(HttpPostedFileBase excelfile)
{
if (excelfile == null || excelfile.ContentLength == 0)
{
ModelState.AddModelError("empty", "some error message");
return RedirectToAction("Index", "DataUpload");
}
else
{
if (excelfile.FileName.EndsWith(".xls") || excelfile.FileName.EndsWith(".xlsx"))
{
string path = System.Web.HttpContext.Current.Server.MapPath("~/Content/" + excelfile.FileName);
if (System.IO.File.Exists(path))
System.IO.File.Delete(path);
excelfile.SaveAs(path);
return View("success");
}
else
{
return View("Index");
}
}
}
}
}
当我执行代码时,我得到了这个错误:
“/”应用程序中的服务器错误。
'~/Content/C:\Documents and Settings\adryan\My Documents\test.xlsx' 不是有效的虚拟路径。 说明:在执行当前 Web 请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
你能帮我解决这个问题吗?
【问题讨论】:
标签: c# asp.net asp.net-mvc file-upload