Get published values ​​from dynamically added controls in ASP.NET MVC

I have a form in which I dynamically add controls through jQuery. I need to access the values ​​in these controls (text fields) when submitting the form to the server. I'm sure this is a trivial problem, but I just can't get around it.

Any help would be greatly appreciated.

+3
source share
1 answer

When adding multiple controls to a page, give them all the same attributes nameso that 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 code will like it

<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" />
+5
source

Source: https://habr.com/ru/post/1793796/


All Articles