3

I have a form in which i'm dynamically addding controls through jQuery. I need to access the values in those controls (textboxes) when posting back the form to the server. I'm sure this is a trivial problem but i just can't get my head around it.

Any help would be greatly apreciated.

1 Answer 1

6

When adding a multiple controls to the page, give them all the same name attribute so you can do the following in your action:

public ActionResult MyAction(string[] items)
{
     // items will contain all the values in the text boxes
    return View();
}

So your HTML would like like this

<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
<input type="text" name="items" />
Sign up to request clarification or add additional context in comments.

Comments

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.