views:

36

answers:

1
+1  Q: 

Html TextBox Array

I have a list of textboxes as an array created using jQuery

<input type="text" name="salaries[]" value="100,000">
<input type="text" name="salaries[]" value="200,000">
<input type="text" name="salaries[]" value="300,000">
<input type="text" name="salaries[]" value="400,000">

Now in C# :

Request.Form["salaries[]"] gives salaries[] = 100,000,200,000,300,000,400,000 Now I am unable to split the values as the commas get mixed up How can this split be achieved?

+2  A: 

You can't fix it on the server, you have to fix the problem on the client first.

One method is to use unique names for each textbox. ie

<input type="text" name="salaries[0]" value="100,000">
<input type="text" name="salaries[1]" value="200,000">
<input type="text" name="salaries[2]" value="300,000">
<input type="text" name="salaries[3]" value="400,000">

And then (assuming you are using mvc??) the controller will be like this

public void save(String[] salaries) { ...

If not mvc, iterate over all parameters with a name starting with salaries

Iain