Ordinary html links in mvc razor

丶灬走出姿态 提交于 2019-12-24 04:23:11

问题


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:


~/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>


来源:https://stackoverflow.com/questions/20339255/ordinary-html-links-in-mvc-razor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!