我能够成功地从数据库获取记录到视图。
当记录较少时,将正确加载视图,但是 当我尝试获取所有记录数(大约29000)
查看:
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">
User Role Management
</div>
<!-- /.panel-heading -->
<div class="panel-body">
@Html.Partial("pv_UserRoleCompany", Model)
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
部分视图:
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
Th goes here...
</tr>
</thead>
<tbody>
@foreach (var item in Model.TypeList)
{
<tr>
<td>
.......
</td>
</tr>
}
</tbody>
控制器:
public ActionResult GetAllUserRoleCompany(String Organisation, String RoleName, String UserName, int UserStatus)
{
LMTUsage objLMT = new LMTUsage();
LMTDAL objLMTDAL = new LMTDAL();
string usrNameWithDomain = System.Web.HttpContext.Current.User.Identity.Name;
//string userID = "261213"; // Environment.UserName;
string userID = "100728";
ViewBag.UserRoleId = objLMTDAL.GetRoleID(userID);
objLMT.TypeList = objLMTDAL.UserRoleCompany_GetAll(Organisation, RoleName, userID, ViewBag.UserRoleId, UserName, UserStatus);
// return Json(objLMT, JsonRequestBehavior.AllowGet);
return PartialView("pv_UserRoleCompany", objLMT);
}
下面是屏幕截图,
注意: 从SQL Server查询在9秒钟内执行了所有29000条记录,但是在视图上显示这些记录却是一个问题,因为它不断不断地加载页面。
谢谢
答案 0 :(得分:0)
我建议服务器端分页。请点击此链接 Server side paging in asp.net mvc
您还可以考虑通过引入数据库侧分页来减少从SQL Server到Web应用程序的数据开销。这是数据库分页的简单示例。 https://www.mssqltips.com/sqlservertip/2362/overview-of-offset-and-fetch-feature-of-sql-server-2012/