获取当前片段路线,ASP.net MVC [英] Get current fragment in Route, ASP.net MVC
问题描述
有没有去从已通过操作链接发出的路由中得到当前片段。这就是我如何得到从路径的操作。
字符串currentAction = requestContext.RouteData.Values [行动]作为字符串? 指数;
块引用>我可以做一些类似的?
字符串currentFragment = requestContext.RouteData.Values [碎片]作为字符串? ;
块引用>解决方案没有,你不能做这样的事。该片段(下面的
#
标志中的URL一切)永远不会被浏览器发送到服务器,所以在谈论仅仅让URL片段服务器端的唯一事实没有意义。所以,如果你有以下网址:
http://example.com/foo/bar?key1=value1#abc
服务器将永远无法获取ABC
仅仅是因为客户端不再发送。Is there away to get the current fragment from a route that was issued via action link. This is how I am getting the action from the route.
string currentAction = requestContext.RouteData.Values["action"] as string ?? "index";
Can I do something similar to this?
string currentFragment = requestContext.RouteData.Values["Fragment"] as string ?? "";
解决方案No, you can't do anything like this. The fragment (everything that follows the
#
sign in an url) is never sent to the server by the browser, so the sole fact of talking about getting the url fragment server side simply doesn't make sense.So if you have the following url:
http://example.com/foo/bar?key1=value1#abc
the server will never be able to fetchabc
simply because the client will never send it.这篇关于获取当前片段路线,ASP.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!