views:

54

answers:

1

Hi, 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 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

+1  A: 

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");
    }
DevDave
i want to display pdf in view in HTMl not to download.
anil
I understand. I am not sure you can do this without using a viewer of some sort. I did some searching and found some ways you can try and force adobe reader to show in the web page but it doesn't work on all browsers. Plus adobe reader has preferences which allow the user to not allow the PDF to open in the browser with adobe reader.
DevDave
so there is no solution to this problem?
anil