我已经从我的模型中的列表中生成了文本框,如下所示: -
@using (Ajax.BeginForm("Create", "Invoice", new AjaxOptions { OnBegin = "OnBegin", OnComplete = "OnCreateComplete" }))
{
<table>
<tr>
<td>@Html.EditorFor(m => m.InvoiceItems[0].Title, new { @placeholder = "Title" }) @Html.ValidationMessageFor(m => m.InvoiceItems[0].Title)</td>
<td>@Html.EditorFor(m => m.InvoiceItems[0].Description, new { @placeholder = "Description" }) @Html.ValidationMessageFor(m => m.InvoiceItems[0].Description)</td>
<td>@Html.EditorFor(m => m.InvoiceItems[0].Amount, new { @placeholder = "Amount" }) @Html.ValidationMessageFor(m => m.InvoiceItems[0].Amount)</td>
</tr>
<tr>
<td>@Html.EditorFor(m => m.InvoiceItems[1].Title, new { @placeholder = "Title" }) @Html.ValidationMessageFor(m => m.InvoiceItems[1].Title)</td>
<td>@Html.EditorFor(m => m.InvoiceItems[1].Description, new { @placeholder = "Description" }) @Html.ValidationMessageFor(m => m.InvoiceItems[1].Description)</td>
<td>@Html.EditorFor(m => m.InvoiceItems[1].Amount, new { @placeholder = "Amount" }) @Html.ValidationMessageFor(m => m.InvoiceItems[1].Amount)</td>
</tr>
<tr>
<td>@Html.EditorFor(m => m.InvoiceItems[2].Title, new { @placeholder = "Title" }) @Html.ValidationMessageFor(m => m.InvoiceItems[2].Title)</td>
<td>@Html.EditorFor(m => m.InvoiceItems[2].Description, new { @placeholder = "Description" }) @Html.ValidationMessageFor(m => m.InvoiceItems[2].Description)</td>
<td>@Html.EditorFor(m => m.InvoiceItems[2].Amount, new { @placeholder = "Amount" }) @Html.ValidationMessageFor(m => m.InvoiceItems[2].Amount)</td>
</tr>
</table>
<input type="submit" value="Create" />
}
如果我提交这个,它会将所有行发布到控制器。但是如果我删除任何像第二行这样的随机行,它只会将第一行发布到控制器。
现在我可以编写一个逻辑来获取控制器上的所有有效行,就像我使用javascript设置一个skip_rows变量并在我的控制器中编写一个循环来读取基于表单行和skip_value的行一样。但不是这个,我正在寻找一些更好的方法。
请指教。