开发者

Get posted values from dynamically added controls in ASP.NET MVC

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 sur开发者_StackOverflowe this is a trivial problem but i just can't get my head around it.

Any help would be greatly apreciated.


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" />
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜