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?

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

4 Comments

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?
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?
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.
That was the missing piece of the puzzle. Put it in /Content and bingo. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.