如何在 mvc 视图中获取路由和查询字符串值

发布于 2024-12-14 10:28:13 字数 181 浏览 3 评论 0原文

如果我有这个 URL:

http://stackoverflow.com/question/ask?type=great

如何最经济地获取视图中的完整路由和查询字符串值,例如这个

/question/ask?type=great

If I have this URL:

http://stackoverflow.com/question/ask?type=great

How do I get the complete route and query string values in the View most economically eg this

/question/ask?type=great

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

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

发布评论

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

评论(2

不语却知心 2024-12-21 10:28:13

如果你想从视图中访问它,你可以使用 httpcontext,

如下所示:

@HttpContext.Current.Request.Path

If you want to get to it from the View, you could use httpcontext

like this:

@HttpContext.Current.Request.Path
少钕鈤記 2024-12-21 10:28:13

您可以在控制器中设置操作方法来自动为您解析查询字符串。您无需对路线执行任何操作。

获取 mvc 中的查询字符串值

you can set the action method in your controller to automatically parse the query string for you. You don't need to do anything to your route.

get query string values in mvc

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文