如何找到用于在 MVC 中调用我的控制器的 href

发布于 01-07 01:19 字数 77 浏览 2 评论 0原文

从控制器操作内部,我想获取单击以进入操作的完整 href 地址。

这可能吗?如果可以的话,我怎样才能在 MVC 中得到它呢?

From inside a controller action I would like to get the full href address that was clicked on to get me to the action.

Is this possible and if so then how can I get that in MVC?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

ㄖ落Θ余辉2025-01-14 01:19:07

您可以使用当前的 UrlReferrer 属性请求:

Request.UrlReferrer

这将读取 Referer 来自请求的 HTTP 标头,可能由客户端(用户代理)提供,也可能不提供。

You could use the UrlReferrer property of the current request:

Request.UrlReferrer

This will read the Referer HTTP header from the request which may or may not be supplied by the client (user agent).

洛阳烟雨空心柳2025-01-14 01:19:07

如果用户点击一个链接,例如路由到您的控制器和操作的 Link,您可以获得 [url_here] 的 url通过调用 Request.Url.ToString() 在操作方法中。

If a user clicks on a link, say <a href='[url_here]'>Link</a> that routes to your controller and action, you can get the url of [url_here] inside the action method by calling Request.Url.ToString().

烟织青萝梦2025-01-14 01:19:07

除了其他人所说的关于 Request.UrlReferrer 之外,您还可以将其作为查询字符串参数传递:

@Html.ActionLink("click me", "foo", new { url = Request.RawUrl })

并在操作内:

public ActionResult Foo(string url)
{
    ...
}

In addition to what others have said about the Request.UrlReferrer you could also pass it as query string parameter:

@Html.ActionLink("click me", "foo", new { url = Request.RawUrl })

and inside the action:

public ActionResult Foo(string url)
{
    ...
}
不美如何2025-01-14 01:19:07
string fullPath = Request.Url.AbsoluteUri
string fullPath = Request.Url.AbsoluteUri
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文