我想在MVC的视图中显示PDF,跟随函数返回文件
public ActionResult TakeoffPlans(string projID)
{
Highmark.BLL.Models.Project proj = GetProject(projID);
List<File> ff = proj.GetFiles(Project_Thin.Folders.CompletedTakeoff, false);
ViewData["HasFile"] = "0";
if (ff != null && ff.Count > 0 && ff.Where(p => p.FileExtension == "pdf").Count() > 0)
{
ViewData["HasFile"] = "1";
}
ViewData["ProjectID"] = projID;
ViewData["Folder"] = Project_Thin.Folders.CompletedTakeoff;
//return View("UcRenderPDF");
string fileName = Server.MapPath("~/Content/Project List Update 2.pdf");
return File(fileName, "application/pdf", Server.HtmlEncode(fileName));
}
但是它显示了一些不良数据,请帮我解决这个问题
答案 0 :(得分:1)
以下控制器方法是否适合您。我目前使用这种控制器方法在我的网站上制作可下载的简历。
public FileResult DownloadResumePdf()
{
string filename = Server.MapPath("~/Content/Downloads/Resume.pdf");
return File(filename, "application/pdf", "Resume.pdf");
}