0

So my client gave me a MVC site that was created and set up my another vendor. I have never worked with MVC until now so I am learning as I go. I was given a small up date to the site where the client needs a link to PDF, which will then open in the browser window. I added the PDF and added a new route and action in the Controller. The following is the code I added:

Home Controller Code

public ActionResult ViewPDF()
{
    return Redirect("Assets/PDF/myPDF.pdf");
}

Route Code

routes.MapRoutesLowercase(
    "Home-ViewPDF",
    "myPdf.pdf",
    new { controller = "Home", action = "ViewPDF" }
);

HTML Code

<a href="<% Url.Action("ViewPDF", "Home") %>"></a>"

Now when I test locally the link works and all is good. When I promote to my Development server I click the link and I get "The page cannot be found". But I know the file is on the server be cause if I type the path in the pdf comes up with no problem.

I have looked every where but cannot find anything online that comes close to what I am looking for, as far as I know that is.

I should note that before I was using Redirect in the Controller I was using a FileResult and returning the File with type application/PDF. However while I was debugging I tried the current method and like I said it worked locally but not on DEV.

Any help would be extremely helpful!! Thanks!

tereško
  • 58,060
  • 25
  • 98
  • 150
jpalladino84
  • 2,480
  • 2
  • 15
  • 16

1 Answers1

0

You should not link to the file directly.

Changing folder structure will result in an application pool recycle for one.

Have a look at: MVC open pdf file

Community
  • 1
  • 1
Eben Roux
  • 12,983
  • 2
  • 27
  • 48
  • As I said I used that method before which is fine I have all the code in place just commented out. However that does not resolve my issue as the problem still persists with the solution you are suggesting. – jpalladino84 Apr 03 '12 at 18:14
  • If you are getting status 404 for the FileResult it means that you are probably not reaching your Action. Have you tried just returning some plain html/text to see what is happening? Maybe check the http traffic? – Eben Roux Apr 03 '12 at 18:19