ASP.NET 4.0 路由 +阿贾克斯浏览器历史记录
ASP.NET 4.0 路由的问题是 Page.RouteData.Values 不包含链接中的 #
字符之后的参数
System.Web.Routing.RouteTable.Routes.MapPageRoute("ProjectViewRoute1",
"project/{title}/{idProject}#{idDesign}", "~/ProjectView.aspx");
正如我所说, Page.RouteData.Values.ContainsKey( "idDesign")
将返回 false
我想使用此功能的原因是因为我使用 JavaScript 和 Ajax 来隐藏一些内容并加载新内容,这在用户眼中就像加载不同的页面一样,他必须能够复制粘贴 URL 并稍后查看该页面。
问题是:如何从 RoutedData 获取 {idDesign}
?
The problem with ASP.NET 4.0 routing is that the Page.RouteData.Values does not contain the paramenters after #
character from the link
System.Web.Routing.RouteTable.Routes.MapPageRoute("ProjectViewRoute1",
"project/{title}/{idProject}#{idDesign}", "~/ProjectView.aspx");
As I said, the Page.RouteData.Values.ContainsKey("idDesign")
will return false
The reason I want to make use of this feature is because I use JavaScript and Ajax to hide some content and load new one, wich in eyes of an user is like loading a different page, and he must be able to copy paste the URL and view that page later.
The question is: how to get the {idDesign}
from the RoutedData ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
浏览器不会将 URL 中的
#
之后的数据发送到服务器;因此,ASP.Net 无法捕获该数据并将其提供给您。我建议使用
?
而不是#
来获取所需的功能,并包含 AJAX 调用来捕获要发送到的 url 哈希部分中的数据服务器(如有必要)用于 AJAX 创建的 url。使用 jQuery:
Browsers don't send data after the
#
in the URLs to the server; as a result, it is not possible for ASP.Net to capture that data and provide it to you.I would recommend using a
?
instead of your#
to get the functionality you need, and include an AJAX call to capture data placed in the hash section of the url to send to the server, if necessary, for AJAX-created urls.Using jQuery: