使用jQuery DataTables + C#Asp.NET MVC 5和服务器端功能,我为DataTable ajax请求构建了一个代表性的类(由official documentation指导):
public class Query
{
public List<QueryColumn> columns { get; set; }
public List<QueryOrder> order { get; set; }
public QuerySearch search { get; set; }
public int draw { get; set; }
public int start { get; set; }
public int length { get; set; }
public string dtid { get; set; }
}
public class QuerySearch
{
public string value { get; set; }
public string regex { get; set; }
}
public class QueryColumn
{
public string data { get; set; }
public string name { get; set; }
public bool searchable { get; set; }
public bool orderable { get; set; }
public QuerySearch search { get; set; }
}
public class QueryOrder
{
public enum Order
{
asc, desc
}
public int column{ get; set; }
public Order dir { get; set; }
}
所有这些都遵循JSON属性映射要求的小写字母。另外,在javascript DataTable初始化中,我添加了所有列的定义:
$("#mydatatable").DataTable({
serverSide: true,
processing: true,
info: true,
order: [[0, 'asc']],
ajax: {
data: function (d) {
// Extra params to request
d.dtid = iddt;
},
url: '@Url.Action("Home", "ListEntities")',
dataType: 'json',
method: 'POST',
dataSrc : "entities"
}
lengthMenu: [[15, 50, 100], [15, 50, 100]],
pageLength : 15,
columns: [
{ name: "Entidad", data: "NombreEntidad", title: "Entidad" },
{ name: "Numero", data: "Numero", title: "Numero" },
{ name: "Fecha", data: "Fecha", title: "Fecha" },
{ name: "Estado", data: "Estado", title: "Estado" },
{ name: "ConsignadoA", data: "ConsignadoA", title: "Consignado a:" },
{ name: "Identificador", data: "Id", "searchable": false, "sortable": false, title: "Acciones" }
]
});
此时,一切看上去都很正确,但是调试请求时,它填充了Query类,但列和订单子列表除外,如图所示:
知道为什么会这样吗?