public ActionResult GetAttachment1(string projectID)
{
return File("~/Uploads/Project", "application/pdf", projectID);
}
此代码出错......
答案 0 :(得分:4)
您需要指定File
方法的绝对路径。使用Server.MapPath
将亲戚转换为绝对路径:
public ActionResult GetAttachment1(string projectID)
{
string projectPath = Server.MapPath("~/Uploads/Project");
string file = Path.Combine(projectPath, projectID);
// at this stage file will look something like this
// "c:\inetpub\wwwroot\Uploads\Project\foo.pdf". Make sure that
// this is a valid PDF file and pass it to the File method
return File(file, "application/pdf", projectID);
}