我有一个这样的表格
<table>
<thead>
<tr>
<th>Tên học sinh </th>
<th>Giáo lý viên </th>
<th>Năm Học</th>
<th>Điểm TB Học Kỳ 1 </th>
<th>Điểm TB Học Kỳ 2 </th>
<th>Điểm Tổng Kết Năm Học </th>
<th>Lớp </th>
</tr>
</thead>
@using (Html.BeginForm())
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset class="form-horizontal">
<tbody id="addDetails">
<tr>
<td>
@Html.DropDownList("HocSinhId", String.Empty)
@Html.ValidationMessageFor(model => model.HocSinhId, null, new { @class = "help-inline" })
</td>
<td>
@Html.DropDownList("GiaoLyVienId", String.Empty)
@Html.ValidationMessageFor(model => model.GiaoLyVienId, null, new { @class = "help-inline" })
</td>
<td>
@Html.TextBoxFor(model => model.NamHoc)
@Html.ValidationMessageFor(model => model.NamHoc, null, new { @class = "help-inline" })
</td>
<td>
@Html.EditorFor(model => model.DiemTBHK1)
@Html.ValidationMessageFor(model => model.DiemTBHK1, null, new { @class = "help-inline" })
</td>
<td>
@Html.EditorFor(model => model.DiemTBHK2)
@Html.ValidationMessageFor(model => model.DiemTBHK2, null, new { @class = "help-inline" })
</td>
<td>
@Html.EditorFor(model => model.DiemTongKetNamHoc)
@Html.ValidationMessageFor(model => model.DiemTongKetNamHoc, null, new { @class = "help-inline" })
</td>
<td>
@Html.DropDownList("LopId", String.Empty)
@Html.ValidationMessageFor(model => model.LopId, null, new { @class = "help-inline" })
</td>
</tr>
</tbody>
<tfoot>
<tr>
<td>
@Ajax.ActionLink("Add", "AddDetails", new AjaxOptions
{
HttpMethod = "GET",
OnSuccess = "successCall",
@*UpdateTargetId = "addDetails",
InsertionMode = InsertionMode.InsertAfter,*@
})
</td>
</tr>
<tr>
<td colspan="6">
@*<a href="#"> </a>*@
<input type="submit" value="Lưu thông tin" class="button" />
</td>
</tr>
</tfoot>
</fieldset>
}
</table>
单击Ajax链接“添加”后,将插入新行以输入新数据。
图片:http://i808.photobucket.com/albums/zz1/nquangkhaiDST/Postmultipledata_zps5364f0a0.png
问题:当我提交给服务器时,它只是发布了第一个数据,而不是我点击“添加”后的数据。我如何从ajax获取所有数据甚至字段回发到服务器。
任何人都知道如何发布所有数据,甚至是ajax的数据。非常感谢
答案 0 :(得分:0)
假设您在单击Add
时添加相同类型的对象,您需要做的是在Post控制器参数中接受模型对象的数组。
[HttpPost]
public ActionResult(MyObject[] objects)
{
// do something
}
答案 1 :(得分:0)
你在客户端检查你的html ....从客户端提交你必须确保页面上添加的控件必须具有命名约定,如
<input type="text" value="" name="IncomeDetails[0].IncomeCode" id="IncomeDetails_0__IncomeCode" class="incomeCode valid" disabled="disabled">
在第一行和
<input type="text" disabled="disabled" class="incomeCode valid" id="IncomeDetails_1__IncomeCode" name="IncomeDetails[1].IncomeCode" value="">
在第二行,然后只有在提交时才能获得完整的对象列表。