【发布时间】:2017-10-21 20:03:43
【问题描述】:
我将视图中的数据绑定到控制器,所以以后我可以对数据做我想做的事。在我的视图中,我使用dataTable 和@Html.EditorForModel() 来呈现我的视图。
查看
<form action="xx" method="POST">
<table id="myTable" class="table table-bordered table-hover table-striped">
<thead>
<tr>
<th></th>
<th>
@Html.DisplayNameFor(model => model.Field1)
</th>
<th>
@Html.DisplayNameFor(model => model.Field2)
</th>
<th>
@Html.DisplayNameFor(model => model.Field3)
</th>
</tr>
</thead>
<tbody>
@if (Model != null)
{
@Html.EditorForModel()
}
</tbody>
<tfoot></tfoot>
</table>
<input type="submit" value="submit" />
</form>
脚本
$("#myTable").dataTable({
searching: false,
ordering: false,
responsive: true,
"bLengthChange" : false,
"pageLength": 20,
"bStateSave": true
});
控制器
[HttpPost]
public ActionResult MyAction(List<MyModel> MyListModel)
如果dataTables 中的数据不超过 1 页,则此方法非常有用。如果超过 1 页,则 My Controller 要么只能接收第一页的 List Data,要么什么都不接收(null)
我应该如何将 DataTables 中的所有数据从 View 绑定到 Controller?此绑定应包括所有页面,而不仅仅是第一个页面
【问题讨论】:
标签: c# jquery asp.net-mvc datatables