获取当前片段路线,ASP.net MVC [英] Get current fragment in Route, ASP.net MVC

查看:81
本文介绍了获取当前片段路线,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 fetch abc simply because the client will never send it.

这篇关于获取当前片段路线,ASP.net MVC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆