使用超链接控制的 ASP MVC
我有以下超链接控件:
<asp:HyperLink ID="hypTest" runat="server" NavigateUrl="~/Views/TestFolder/TestPage.aspx" >
Text here
</asp:HyperLink>
但它找不到该页面 - 尽管该页面确实存在。我得到的错误是:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Views/TestFolder/TestPage.aspx
我的猜测是波形符 (~) 在这里不起作用。如果是这种情况,那么为什么,我该如何解决呢?
I have the following hyperlink control:
<asp:HyperLink ID="hypTest" runat="server" NavigateUrl="~/Views/TestFolder/TestPage.aspx" >
Text here
</asp:HyperLink>
But it doesn't find the page - although the page does exist. The error that I get is:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
Requested URL: /Views/TestFolder/TestPage.aspx
My guess is that the tilde (~) doesn't work here. If this is the case then why, and how can I get around it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 MVC,则应该使用
HtmlHelper.ActionLink
辅助函数。您现在正在使用网络表单超链接控件。假设您有默认路由,您应该能够使用您当前收到 404 错误,因为默认情况下会阻止
~/View
文件夹中的页面。您通常会在~/TestFolder/TestPage
处请求该页面。If you are using MVC you should use
HtmlHelper.ActionLink
helper function. You are using a webforms hyperlink control at the moment. Assuming that you have default routing you should be able to useYou are currently getting a 404 error as pages within the
~/View
folder are blocked by default. You would typically request the page at~/TestFolder/TestPage
.