3

我正在使用MapPageRoute路由到页面,它工作正常。但是,我希望页面滚动到底部以显示某个divid bottom。我试图制作以下路线,但哈希值已在 URL 中编码,因此页面不会向下滚动。

RouteTable.Routes.MapPageRoute("Topics", 
 "onderwerpen/{ID}/{name}#bottom", 
 "~/TopicPage.aspx"
);

结果是:

mydomain/onderwerpen/1/title%23bottom

当这样调用时:

Response.RedirectToRoute("Topics", new { ID = 1, name = "title" });
4

2 回答 2

2

我想我自己找到了最合适的解决方案。这个答案是开放的讨论。

string url = Page.GetRouteUrl("Topics", new { ID = 1, name = "title" });
Response.Redirect(url + "#bottom");
于 2012-04-30T09:37:12.340 回答
0

您将无法使用 重定向到锚点Response.RedirectToRoute()。在您提供的代码中,routeUrl参数包含#bottom锚点。锚标记不属于其中,routeUrl因为routeUrl它是用于匹配传入请求的表达式。并将锚附加#bottom到第三个参数:physicalFile将不起作用,因为正如参数名称所暗示的那样,您指定的是 Web 服务器上的文件名,而不是 URL。

为什么不直接使用 good ol'Response.Redirect()呢?

Response.Redirect("onderwerpen/1/title#bottom");
于 2012-04-29T14:29:19.607 回答