我现在正在做这件事。我正在使用 ASP.Net MVC 2 Web 应用程序,虔诚地使用数据表,并且需要在每个表上显示超过 1000 条记录。服务器端处理是我要走的路。这就是我们所拥有的。
这是我们在视图中的声明(/Admin/Unassigned)。
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#adminUnassignedTable').dataTable({
"bProcessing": true,
"bServerSide": true,
"sAjaxSource": "/Admin/UnassignedTable"
});
});
</script>
这是我们的控制器函数(/Admin/UnassignedTable)。
public void UnassignedTable()
{
statusID = (int)PTA.Helpers.Constants.Queue;
locationID = (int)PTA.Helpers.Constants.Reviewer;
_AdminList = PTA.Models.IPBRepository.GetIPBsByStatus(Convert.ToInt32(statusID), Convert.ToInt32(locationID)); //_AdminList is an IEnumerable<IPB>, IPB being our class
IEnumerable<IPB> _NewList;
int nDisplayStart = Convert.ToInt32(HttpContext.Request.QueryString.Get("iDisplayStart");
int nDisplayLength = Convert.ToInt32(HttpContext.Request.QueryString.Get("iDisplayLength");
_NewList = _AdminList.Skip<IPB>(nDisplayStart).Take<IPB>(nDisplayLength).ToList<IPB>();
string strOutput = "{";
strOutput += "\"sEcho\":" + HttpContext.Request.QueryString.Get("sEcho") + ", ";
strOutput += "\"iTotalRecords\":" + _AdminList.Count().ToString() + ", ";
strOutput += "\"iTotalDisplayRecords\":" + _AdminList.Count().ToString() + ", ";
strOutput += "\"aaData\":[";
foreach (IPB ipb in _NewList)
{
strOutput += "[ ";
strOutput += "\"" + ipb.IPBName + "\",";
strOutput += "\"" + ipb.PubDate + "\",";
strOutput += "\"" + ipb.Change + "\",";
strOutput += "\"" + ipb.ChangeDate + "\",";
strOutput += "\"" + ipb.TotalParts + "\",";
strOutput += "\"" + ipb.TotalPartsReports + "\",";
strOutput += "\"" + ipb.ALC + "\",";
strOutput += "\"" + ipb.DateAdded + "\",";
strOutput += "\"" + "" + "\","; //Need to add drop down control, that's why it's blank.
strOutput += "\"" + "" + "\","; //Need to add drop down control, that's why it's blank.
strOutput += "\"" + "" + "\","; //Need to add drop down control, that's why it's blank.
strOutput += "\"" + "" + "\""; //Need to add drop down control, that's why it's blank.
strOutput += "]";
if (ipb != _NewList.Last())
{
strOutput += ", ";
}
}
strOutput += "]}";
Response.Write(strOutput);
}
笔记!!!!!!!添加控件时,您必须将控件值的引号作为 \\" 因为反斜杠需要在 JSON 数据中。
希望在控制器中您可以访问您的网络服务。我对网络编程不太熟悉,所以我不知道你需要做什么。我只是认为这会有所帮助。