如何获取当前操作的url(修改一些路由数据后)?
我正在通过母版页中的更改语言控件本地化站点。我需要使用您当前所在的每种不同语言的 url 来呈现控件。
因此,如果您访问 http://site.com/en/Home/关于您将语言更改为法语,我需要引导您访问 http://site.com/fr/主页/关于。
本地化代码适用于路由数据语言属性,因此我一直在尝试弄清楚如何:
- 获取对当前操作(包含所有原始参数)的访问
- 权限 获取当前操作(包含所有原始参数)的 url路线数据发生变化。
有人能指出我正确的方向吗?
我尝试将 ViewContext 从父级传递到 UserControl,这使我可以访问路由数据,但我不知道如何从中获取语言路由 url。
I'm localising a site via a Change Language control in the master page. I need to render the control with the current url you're on in each of the different languages.
So if you're on http://site.com/en/Home/About and you change the language to french, I need to direct you to http://site.com/fr/Home/About.
The localisation code works on the route data language property, so I've been trying to figure out how I can:
- Get access to the current action (with all original parameters)
- Get the url to the current action (with all original parameters) with the route data changed.
Can anyone point me in the right direction?
I've tried passing the ViewContext from the parent into the UserControl, which gives me access to the route data but I can't figure out how to get the language routed url from that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在我正在本地工作的网站上运行了这个,它似乎有效。可能有一种更清洁的方法。
显然,+1 甚至可以出现在 IF 语句中,但我认为它在那里看起来不太好。希望这对一些人有帮助。
I ran this on the site I'm working on locally and it seemed to work. There's probably a cleaner way.
Obviously the +1 can even go in the IF statement, but I didn't think it looked good there. Hope this helps some.
我对此并不是百分百满意,我还没有达到可以充分测试其影响的阶段,但这就是我到目前为止所要做的。如果您有更好的解决方案,请回复。
我从母版页传递 ViewContext,以便从您当前所在的任何 url 获取带有路由数据的 ViewContext。
I'm not 100% happy with this, I haven't got to a stage where I can fully test the impact of this but this is what I'm going for so far. Please do answer if you have a better solution.
I pass the ViewContext from the masterpage so I get the ViewContext with route data from whatever url you're currently on.