使用超链接控制的 ASP MVC

发布于 2024-10-29 16:14:14 字数 582 浏览 1 评论 0原文

我有以下超链接控件:

<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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

未蓝澄海的烟 2024-11-05 16:14:14

如果您使用 MVC,则应该使用 HtmlHelper.ActionLink 辅助函数。您现在正在使用网络表单超链接控件。假设您有默认路由,您应该能够使用

<%=Html.ActionLink("Text here", "TestPage", "TestFolder")%>

您当前收到 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 use

<%=Html.ActionLink("Text here", "TestPage", "TestFolder")%>

You 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文