0

我有这样的表格

<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 的数据。十分感谢

4

2 回答 2

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="">

在第二行,只有在提交时您才能获得完整的对象列表。

于 2013-09-04T05:38:11.190 回答
0

假设您将在单击时添加相同类型的对象Add,您需要做的是在 Post 控制器参数中接受模型对象的数组。

[HttpPost]
public ActionResult(MyObject[] objects) 
{
// do something
}
于 2013-09-03T15:39:25.520 回答