views:

60

answers:

1

http://www.plus2net.com/php%5Ftutorial/array%5Fcheckbox.php

the link is my reference in PHP

i want to ask how can i archive the samething with 2d array of data in asp.net mvc. if posible please show me some example, i can't find any info. I remember that php did this very easy. or even in ruby on rails.

elementname[][]

thank you

A: 

If you have a bunch of checkboxes with the same name:

<input type="checkbox" name="box" value="Freddy" />
<input type="checkbox" name="box" value="Brian" />
<input type="checkbox" name="box" value="John" />
<input type="checkbox" name="box" value="Roger" />

You just do this to get the checked values:

string[] values = Request.QueryString.GetValues("box");
Guffa
Request.Form.GetValues if it is a Post.
Yuriy Faktorovich
THis is pretty bad practice in ASP.NET MVC though - you want to stay clear of calls to `Request` and all it's tail. However, the same could probably be accomplished with a model binder, custom if the standard one can't do it.
Tomas Lycken
however, if im using multiple row? for example, 1 row may have 2 or 3 checkbox. what should i do?
DucDigital
@DucDigital: It doesn't matter how the fields are arranged on the page, it only matters what names they have. You may want to give the checkbox on the same row the same name, but different names for each row, so that you can get a row as a list, but each row separately.
Guffa