循环遍历VB.NET中的request.querystring

pln*_*txt 3 vb.net query-string

我试图循环查询字符串并提取某些值,如:

?ProductID=1234&ProductID=4321&Quantity=1
Run Code Online (Sandbox Code Playgroud)

对于ProductID旁边的每个值,我想执行一些逻辑.但我不确定如何达到价值观.有任何想法吗?

Jas*_*tes 7

当您的查询字符串具有多个具有相同键的值时,您可以使用返回字符串数组的NameValueCollection.GetValues方法:

dim productID as string
for each productID  in Page.Request.QueryString.GetValues("ProductID")
  ' do something with productID
next productID  
Run Code Online (Sandbox Code Playgroud)


Jam*_*mes 5

这是一些未经测试的伪代码,它们应该适用于页面背后的代码。我希望这有帮助。

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
Run Code Online (Sandbox Code Playgroud)