简体   繁体   中英

How to pass information from i number of textboxes through an array to the controller

@for(var i = 0; i < ViewBag.numassets; i++){
<tr>
    <td>
    @{
        string assetname = ("Assetname"+Convert.ToString(i));
        @Html.TextBox(assetname, "", new { style = "width:150px" });
        namearray[i] = Convert.ToString(Html.TextBox(assetname));
     }
    </td>

With this code I create a number of textboxes based on the specified amount by user.

Now I'd like to pass the value of these textboxes (could be many textboxes) as an array or list object upon hitting a Submit button. I've got a method in a Model file that is build to deal with arrays so this would be preferable.

The difficulty is with the dynamic textboxes. When I pass Assetname1 for instance it works fine.

如果将它们都命名为相同的名称,则它们应该以数组的形式出现。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM