【问题标题】:How do I get the route and query string values in a mvc view如何在 mvc 视图中获取路由和查询字符串值
【发布时间】:2011-11-07 10:11:48
【问题描述】:

如果我有这个网址:

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

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

/question/ask?type=great

【问题讨论】:

    标签: model-view-controller view


    【解决方案1】:

    如果你想从视图中获取它,你可以使用 httpcontext

    像这样:

    @HttpContext.Current.Request.Path
    

    【讨论】:

      【解决方案2】:

      您可以在控制器中设置操作方法来自动为您解析查询字符串。你不需要对你的路线做任何事情。

      get query string values in mvc

      【讨论】:

      • public actionresult Ask(string type)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      • 2017-09-01
      相关资源
      最近更新 更多