Вопрос

I have query string that has parameters like that: ...&ChildAge=3&ChildAge=4 But collection return me result as "3,4" instead of 3 and 4, with this code:

 Dim a As ArrayList = New ArrayList
        For i = 0 To Request.QueryString("ChildAge").Count
            a.Add(Request.QueryString("ChildAge")(i))
        Next

What's wrong with it? How can I get separated values?

Это было полезно?

Решение

QueryString is a NameValueCollection, therefore duplicate key values are concatenated as comma separated list (from the Add method):

If the specified key already exists in the target NameValueCollection instance, the specified value is added to the existing comma-separated list of values in the form "value1,value2,value3".

You can use GetValues to retrieve a string() for a given key:

Dim childAges As String() = Request.QueryString.GetValues("ChildAge");

Другие советы

Split the parameter into an array of values, then you will be able to iterate through

myArray = Request.QueryString("ChildAge").Split(", ")

You can use like this.

Dim a As ArrayList = New ArrayList
        For i = 0 To Request.QueryString("ChildAge").Count
            a.Add(Request.QueryString("ChildAge").Split(",")(i))
        Next
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top