1

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?

2
  • Before trying to answer your question -- what are you trying to do with the "Entities" list? Are you validating form input values? Can you just use more specific input types (email, tel, url, etc) and the required attribute? Commented Dec 4, 2014 at 5:14
  • The "entities" are codes for business entities that the user can see on-line. They are just strings that we list on the form. If the user has edit access, they can add new ones. Commented Dec 8, 2014 at 22:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.