Reputation: 26922
I'm using MapPageRoute
to make a route to a page, which works fine. However, I would like the page to scroll to the bottom to show a certain div
with id bottom
. I have tried to make the following route but the hash is being encoded in the URL so the page does not scroll down.
RouteTable.Routes.MapPageRoute("Topics",
"onderwerpen/{ID}/{name}#bottom",
"~/TopicPage.aspx"
);
results in:
mydomain/onderwerpen/1/title%23bottom
when called like this:
Response.RedirectToRoute("Topics", new { ID = 1, name = "title" });
Upvotes: 3
Views: 842
Reputation: 26922
I think I found the most suitable solution myself. This answer is open for discussion.
string url = Page.GetRouteUrl("Topics", new { ID = 1, name = "title" });
Response.Redirect(url + "#bottom");
Upvotes: 2
Reputation: 1101
You won't be able to redirect to an anchor using Response.RedirectToRoute()
. In the code you've supplied, the routeUrl
parameter contains the #bottom
anchor. The anchor tag doesn't belong in routeUrl
because routeUrl
is an expression used to match against an incoming request. And appending the #bottom
anchor to the third parameter: physicalFile
won't work because, as the parameter name suggests, you are specifying the name of a file on the web server, not a URL.
Why not just use good ol' Response.Redirect()
?
Response.Redirect("onderwerpen/1/title#bottom");
Upvotes: 0