从ASP.NET MVC中动态添加的控件获取发布值

scr*_*pni 3 asp.net-mvc

我有一个表单,我通过jQuery动态添加控件.在将表单发布回服务器时,我需要访问这些控件(文本框)中的值.我确信这是一个微不足道的问题,但我无法理解它.

任何帮助都会大大减少.

Oma*_*mar 6

向页面添加多个控件时,请为它们指定相同的name属性,以便在操作中执行以下操作:

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

所以你的HTML就像这样

<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" />
Run Code Online (Sandbox Code Playgroud)