1

I'm sure this is very simple...I'm trying to link to a PDF file using Uri.Content but keep getting resource not found errors. The code I am using is:

<a href="@Url.Content("~/Views/MasterPlan/masterplanwithbackground.pdf")">Master Plan</a>

The PDF is located in the Views/MasterPlan directory - usual default MVC project structure.

Thanks.

Eric Yeoman
  • 1,036
  • 1
  • 14
  • 31
  • 2
    Shouldn't the Views Folder contain Views only? Wouldn't it be wiser to create a `~/documents/` folder or something? – Marco Sep 24 '14 at 09:30

3 Answers3

2

You should not be able to route to files in your Views folder out of the box.

You should create a seperate folder called "docs", "documents" or "files" if you want to serve content directly from the filesystem and not from a database. Then there is also "seperation of concerns" - Your Views folder is responsible for containing and serving views to your controller.

The syntax of your Url.Content is correct. Just the path / concept is incorrect.

Marco
  • 22,856
  • 9
  • 75
  • 124
  • Thanks Serv and balexandra, that fixed it. Was not aware of the file permissions on the View folder, so thanks for the info. – Eric Yeoman Sep 24 '14 at 09:43
1

Here is a similar question, but about different file types.

In view folder there is a web.config file, which contain this lines:

<handlers>
      <remove name="BlockViewHandler"/>
      <add name="BlockViewHandler" path="*" verb="*" preCondition="integratedMode" type="System.Web.HttpNotFoundHandler" />
</handlers>

It blocks all request to this folder and its content.

Just create one more folder to store your documents, or place your pdf in folder where you store your ccs, js and image files.

Community
  • 1
  • 1
aleha_84
  • 8,309
  • 2
  • 38
  • 46
-1


Advertisement Notice

You can pass pdf url as dynamically in @url.content() of href="@url.content( )" . Its working fine.

R2Psoft
  • 19
  • 2