我跟随this tutorial实施了带服务器端分页的jquery数据表。
我的问题是:
如何在jQueryDataTableParamModel
中添加自定义属性,以便从视图中将此属性发送到控制器。
注意:它不必位于jQueryDataTableParamModel
类内,每次在控制器操作中作为参数收到CompanyId
时,指向将jQueryDataTableParam
传递给控制器。
public class jQueryDataTableParamModel
{
...
public int CompanyId{ get; set; }
}
控制器动作
public ActionResult GetData(jQueryDataTableParamModel param)
{
...
}
更新:
var oTable = $('#dataTables-table').dataTable({
"sPaginationType": "full_numbers",
"bServerSide": true,
"sAjaxSource": "/Home/Data",
"bProcessing": true,
"fnServerParams": function (aoData) {
aoData.push({ "name": "CompanyID", "value": 555 });
},
"aoColumns": [
{
"sName": "Id",
"bSearchable": false,
"bSortable": false
},
{ "sName": "DATA1" },
{ "sName": "DATA2" },
{ "sName": "DATA3" }
]
});
答案 0 :(得分:0)
哦,我最近使用过JQuery DataTables和Pagination。试试这个:
public ActionResult GroupsDetailAjaxHandler(JQueryDataTableParamModel param, int? CompanyID)
{
var _table = _repo.GetData(CompanyID ?? 0);
return Json(new
{
aaData = from emp in _table
select new[] { emp.item1,emp.item3,emp.item3 }
},
JsonRequestBehavior.AllowGet);
}
Jquery代码
var oGroupsDetail = $('#GroupsDetail').DataTable({
"ajax": "/Home/GroupsDetailAjaxHandler",
"fnServerParams": function (aoData) {
aoData.push({ "name": "CompanyID", "value": yourCompanyIDvariable });
}
});