Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I loop through a Collection.Request.Form?

I have some checkboxes with a unique id. is it possible to find all the checkbox+uniquenum in a form collection?

something like -

foreach (var item in Collection.Request.Form["checkbox" + with UniqueIDNum])
{
    //code
}
like image 348
MrM Avatar asked Jan 26 '11 17:01

MrM


People also ask

Which loop is best used when looping through a collection?

There are several different ways you can loop on the elements of a collection. However, the recommended method for looping on a collection is to use the For Each... Next loop. In this structure, Visual Basic repeats a block of statements for each object in a collection.

What is Request Form collection?

The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POST method. Form input is contained in headers. It is wise to not trust the data that is contained in headers, as this information can be falsified by malicious users.


1 Answers

No.

Instead, you can loop through all of the keys, and check whether they start with checkbox.

For example:

foreach(string key in Request.Form) {
    if (!key.StartsWith("checkbox")) continue;
    ...
}

The NameValueCollection enumerator returns keys as strings.

like image 176
SLaks Avatar answered Oct 04 '22 08:10

SLaks