anil
anil

Reputation: 1

Display PDF in Html

I want to show PDF in a view in MVC, following function return file

 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));
        }

but it display some bad data in view, please help me on this

Upvotes: 0

Views: 495

Answers (1)

DevDave
DevDave

Reputation: 1049

Would the following controller method work for you. I currently use this controller method to make a downloadable resume on my site.

    public FileResult DownloadResumePdf()
    {
        string filename = Server.MapPath("~/Content/Downloads/Resume.pdf");
        return File(filename, "application/pdf", "Resume.pdf");
    }

Upvotes: 1

Related Questions