如何获取 asp.net 核心中的查询字符串参数值?
How to get query string parameter value in asp.net core?
我正在尝试使用以下方法获取查询字符串值:
_httpContextAccessor.HttpContext.Request.QueryString["data"]
但失败并出现错误:
Cannot apply indexing with [] to an expression of type 'QueryString'
QueryString 来自 Microsoft.AspNetCore.Http
命名空间。
一般来说,您应该依赖 model-binding 来访问传入值,而不是从某个请求源显式读取它们。
但是,读取 query-string 值的正确方法是通过 Request.Query
。在你的情况下:
_httpContextAccessor.HttpContext.Request.Query["data"]
我正在尝试使用以下方法获取查询字符串值:
_httpContextAccessor.HttpContext.Request.QueryString["data"]
但失败并出现错误:
Cannot apply indexing with [] to an expression of type 'QueryString'
QueryString 来自 Microsoft.AspNetCore.Http
命名空间。
一般来说,您应该依赖 model-binding 来访问传入值,而不是从某个请求源显式读取它们。
但是,读取 query-string 值的正确方法是通过 Request.Query
。在你的情况下:
_httpContextAccessor.HttpContext.Request.Query["data"]