chugh97
chugh97

Reputation: 9984

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?

Upvotes: 2

Views: 1238

Answers (1)

Iain
Iain

Reputation: 11234

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

Upvotes: 3

Related Questions