Reputation: 16695
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?
Upvotes: 3
Views: 2261
Reputation: 7280
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
.
Upvotes: 7