Asp.net mvc Telerik MVC Razor网格中的自定义分页导致性能问题
我使用的是Telerik MVC网格,我试图在其中填充大约30万条记录。虽然通过服务获取这些数据只需要很少的时间,但在填充这些数据时会出现性能问题。 所以我决定使用自定义分页,一次只加载一个页面数据,但使用Total Recordcount拆分页面需要很长时间 这是我的密码。请帮我做这件事Asp.net mvc Telerik MVC Razor网格中的自定义分页导致性能问题,asp.net-mvc,asp.net-mvc-3,c#-4.0,razor,telerik,Asp.net Mvc,Asp.net Mvc 3,C# 4.0,Razor,Telerik,我使用的是Telerik MVC网格,我试图在其中填充大约30万条记录。虽然通过服务获取这些数据只需要很少的时间,但在填充这些数据时会出现性能问题。 所以我决定使用自定义分页,一次只加载一个页面数据,但使用Total Recordcount拆分页面需要很长时间 这是我的密码。请帮我做这件事 [GridAction(EnableCustomBinding=true,GridName="RunDetails")] public ActionResult RunDetails(stri
[GridAction(EnableCustomBinding=true,GridName="RunDetails")]
public ActionResult RunDetails(string id, GridCommand command)
{
var run = service.GetAllRuns().First(x => x.ID == id);
var itemList = new List<System.Dynamic.ExpandoObject>() ;
try
{
var detail = service.GetStatistic(run);
itemList = detail.Select(x => ((object)x.Inner).ToExpando()).ToList();
if (command.Page == 0 && command.PageSize == 0)
{
command.Page=1;
command.PageSize = 20;
}
ViewData["total"] = itemList.Count;
itemList = itemList.Skip((command.Page - 1) * command.PageSize).Take(command.PageSize).ToList();
}
catch (Exception e)
{
Log.Error("Error while changing the state of the Run = " + e);
}
return View(new StatisticRunModel(run, itemList));
}
**VIEW:**
@{
Html.Telerik().Grid(Model.Items)
.Name("RunDetails")
.DataKeys(keys => keys.Add(x => x))
.EnableCustomBinding(true)
.BindTo(Model.Items)
.Columns(columns =>
{
if (Model.Columns != null)
{
foreach (var col in Model.Columns)
{
if (!col.Contains("ID"))
{
string colname = col.ToString();
columns.Bound(colname);
}
}
}
})
.Sortable(sorting => sorting.SortMode(GridSortMode.MultipleColumn))
.Filterable()
.Pageable(settings => settings.Total((int)ViewData["total"]).PageSize(20))
//.Pageable(paging => paging//.Position(GridPagerPosition.Bottom)
//.Style(GridPagerStyles.NextPreviousAndNumeric)
//.Total((int)ViewData["total"])
//.PageSize(20)) //this also causing same problem
.Render();
}
[GridAction(EnableCustomBinding=true,GridName=“RunDetails”)]
公共ActionResult运行详细信息(字符串id,GridCommand)
{
var run=service.GetAllRuns().First(x=>x.ID==ID);
var itemList=新列表();
尝试
{
var detail=service.GetStatistic(运行);
itemList=detail.Select(x=>((object)x.Inner).ToExpando()).ToList();
if(command.Page==0&&command.PageSize==0)
{
命令页=1;
command.PageSize=20;
}
ViewData[“total”]=itemList.Count;
itemList=itemList.Skip((command.Page-1)*command.PageSize.Take(command.PageSize.ToList();
}
捕获(例外e)
{
Log.Error(“更改运行状态时出错=“+e”);
}
返回视图(新的StatisticRunModel(run,itemList));
}
**视图:**
@{
Html.Telerik().Grid(Model.Items)
.名称(“详细信息”)
.DataKeys(keys=>keys.Add(x=>x))
.EnableCustomBinding(真)
.BindTo(模型项)
.列(列=>
{
如果(Model.Columns!=null)
{
foreach(模型列中的变量列)
{
如果(!col.Contains(“ID”))
{
字符串colname=col.ToString();
columns.bind(colname);
}
}
}
})
.Sortable(排序=>排序.SortMode(GridSortMode.MultipleColumn))
.可过滤()
.Pageable(settings=>settings.Total((int)ViewData[“Total”]).PageSize(20))
//.Pageable(paging=>paging/.Position(GridPagerPosition.Bottom)
//.Style(GridPagerStyles.nextPrevious和Numeric)
//.Total((int)ViewData[“Total”])
//.PageSize(20))//这也会导致相同的问题
.Render();
}
此方法返回service.GetStatistic(run)的内容是什么;。不要返回列表,而是返回iQueryEnable当我尝试绑定20条记录时,我遇到了问题。它为我的30000条记录创建了一个页面,这使得问题..可分页(设置=>settings.Total(20))。。。你试过这个吗?