我正在尝试以 json 格式为 extjs 分页工具栏返回数据列表以及记录总数。extjs 查找“count”以计算分页总数。这是我想要的格式。
{
"count": 1,
"listData": [
{
"LastName": "Beckham",
"FirstName": "David"
}
]
}
这是我的方法
public static List<myList> newRecords(int start, int limit)
{
List<myList> listData = new List<myList>();
using (SqlConnection con = SqlTools.GetSqlConnection())
{
con.Open();
SqlCommand cmd = con.CreateCommand();
cmd.CommandText = "id1_GetData";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@limit", SqlDbType.Int).Value = limit;
cmd.Parameters.Add("@start", SqlDbType.Int).Value = start;
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
myList list1 = new myList();
list1.LastName = reader["LastName"].ToString().Trim();
list1.FirstName = reader["FirstName"].ToString().Trim();
listData.Add(list1);
}
con.Close();
int count = countRecords(); //counts total number of records in db
var pagingData = (new
{
count,
listData
});
//return myList;
return new List<myList>(pagingData);
}
}
这样我什么都得不到……如果我返回 myList,我只会得到第一页。请帮忙