How can I use HTML5 Request.Form to get list values?

707 views Asked by At

I'm new to HTML5. I have a list structure on the form. This is the generated HTML:

<div id="acctCode1">
<input class="entity" id="Entities1_0_" name="Entities1[0]" type="text" value="788" /><br/>
<input class="entity" id="Entities1_1_" name="Entities1[1]" type="text" value="Q83" /><br/>
<input class="entity" id="Entities1_2_" name="Entities1[2]" type="text" value="" /><br/>
</div>

When the Form is posted, I need to get the entity values into a list. Here's my code (I've kept it simple so it's easy to understand):

var ent1 = new string[20];
for (int i = 0; i < ent1.Count; i++)
{
    var entKey = "Entities1[" + i.ToString() + "]";
    var acct = Request.Form[entKey];
    if (!string.IsNullOrEmpty(acct))
    {
        ent1[i] = acct;
    }
    else
    {
        break;
    }
}

The best I can say about this code is that it works. I've looked through the Request and the Form objects and I can't find a better way to get the values.

Isn't there a less kludgey way to pick up all the values from the Entities1 list?

0

There are 0 answers