2

I have an mvc razor app that's humming along nicely, and I just tried to drop in a static html Terms and Conditions page. When I try to link to it from my opt-in cshtml with

<a href="~/Views/UserPromotion/TechFundTnC.html">Terms and Conditions</a>

It 404s at runtime with "resource cannot be found".

It's in the compiled folder. The path and name are correct (I picked it with intellisense, so it knows it's there). The link cshtml page and destination html page are even in the same folder (I've tried using just the filename too).

It's just plain html. It shouldn't need any fiddling with routing or anything. Why can't it find it?

tereško
  • 58,060
  • 25
  • 98
  • 150
SteveCav
  • 6,649
  • 1
  • 50
  • 52

1 Answers1

4

~/Views is inaccessible by default and ~ doesn't work in static HTML, you can use this and it should get you the relative path and work

Put your static HTML file in ~/Content/UserPromotion and use

<a href="@Url.Content("~/Content/UserPromotion/TechFundTnC.html")">Terms and Conditions</a>
Matt
  • 3,143
  • 1
  • 17
  • 14
  • Oh, you're trying to load a HTML file directly, you need a route to a Controller/Action that returns the view. Is that T&C just a static HTML file? – Matt Dec 02 '13 at 22:55
  • Yes, it's just static html in the same(views) folder. I have to make a new controller and action to load a simple html page? – SteveCav Dec 02 '13 at 22:56
  • 1
    No, but I believe the general practice is to put static content in a /Content folder in the root of the application. Your web.config probably doesn't allow direct access to anything in ~/Views. Also, updated answer with this info. – Matt Dec 02 '13 at 23:00
  • That was the missing piece of the puzzle. Put it in /Content and bingo. Thanks. – SteveCav Dec 02 '13 at 23:09