我正在尝试遍历查询字符串并提取某些值,如下所示:
?ProductID=1234&ProductID=4321&Quantity=1
对于 ProductID 旁边的每个值,我想执行一些逻辑。但我不确定如何获得这些价值观。有任何想法吗?
我正在尝试遍历查询字符串并提取某些值,如下所示:
?ProductID=1234&ProductID=4321&Quantity=1
对于 ProductID 旁边的每个值,我想执行一些逻辑。但我不确定如何获得这些价值观。有任何想法吗?
当您的查询字符串具有多个具有相同键的值时,您可以使用返回字符串数组的NameValueCollection.GetValues方法:
dim productID as string
for each productID in Page.Request.QueryString.GetValues("ProductID")
' do something with productID
next productID
这是一些未经测试的伪代码,应该适用于页面后面的代码。我希望这有帮助。
dim key as string
dim list as new arraylist()
for each key in Page.Request.QueryString.Keys
if key = "ProductID" then
list.add(Page.Request.QueryString(key))
end if
next key
' do somthing with the list of product id's
Dim productID = Request.Querystring("ProductID")
Dim quantity = Request.Querystring("Quantity")
Dim sQS as String = Request.QueryString.ToString
For Each eItem In Split(sQS, "&")
Dim sName As String = Left(eItem, InStr(eItem & "=", "=") - 1)
Response.Write(sName _
& " = " & Request.QueryString(sName) _
& "<br>")
Next
这更短但基于相同的想法
For Each Key As String In Request.QueryString.Keys
Response.Write(Key & " = " & Request.QueryString(Key) & "<br>")
Next
试试这个。仅适用于 VB9。
Dim queryString = GetQueryString()
queryString = queryString.SubString(1) 'Remove ?
Dim ids = queryString. _
Split("&"c). _
Select(Function(x) x.Split("="c)). _
Where(Function(x) x(0) = "ProductId" ). _
Select(Function(x) x(1))
供阅读Value
使用get Parameter
Request.QueryString.Item("param")