asp.net-mvc 如何在视图中获取当前 url 值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7323707/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 01:27:10  来源:igfitidea点击:

How to get current url value in View

asp.net-mvcurlview

提问by Tae-Sung Shin

I have following Url:

我有以下网址:

customer/login?ReturnUrl=home

How can I get this string in my view? I tried

我怎样才能在我的视图中得到这个字符串?我试过

RouteData.GetRequiredString("action")

But it does not return full string. Any help will be appreciated.

但它不会返回完整的字符串。任何帮助将不胜感激。

回答by jdavies

Use the HttpRequest.Url.PathAndQueryProperty to retrieve the absolute path and query like so:

使用HttpRequest.Url.PathAndQuery属性来检索绝对路径和查询,如下所示:

<%= Request.Url.PathAndQuery %>