简体   繁体   中英

vb.net handle a post with an array

I'm trying read an array that was post from a html form

<input name="test[]" id="1" type="checkbox" value="1" />
<input name="test[]" id="2" type="checkbox" value="2" />
<input name="test[]" id="3" type="checkbox" value="3" />
<input name="test[]" id="4" type="checkbox" value="4" />

In php I know you can just access the data very easily

foreach($_POST['test'] as $item)
{
    echo $item;
}

I've had a look around and haven't come across anything doing the same thing.

Any help would be greatly appreciated.

If you just get Request("test[]") , you should get back a comma-separated list of the values. I'm not sure how well that'd work if the values can have commas in them.

If you need the values as an array, you can check out Request.Form.GetValues("test[]") . It'll probably be null if no boxes were checked, though, so check for that before you use the array.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM