C# 服务器端分页不适用于第一页kendo grid mvc包装器

C# 服务器端分页不适用于第一页kendo grid mvc包装器,c#,asp.net,asp.net-mvc,kendo-grid,kendo-asp.net-mvc,C#,Asp.net,Asp.net Mvc,Kendo Grid,Kendo Asp.net Mvc,因为如果数据超过15000,我的剑道网格将花费太多时间加载 记录,我想实现服务器端分页 我没有使用实体框架。我正在使用Kendo MVC包装器和SQL 服务器存储过程来拉取和显示数据 我已经向过程传递了两个参数@Skip和@Take 以下是我的代码: 查看 行动: [HandleError(ExceptionType=typeof(Exception),View=“ApplicationError”)] public PartialViewResult DeviceEventExpandedVi

因为如果数据超过15000,我的剑道网格将花费太多时间加载 记录,我想实现服务器端分页

我没有使用实体框架。我正在使用Kendo MVC包装器和SQL 服务器存储过程来拉取和显示数据

我已经向过程传递了两个参数@Skip和@Take

以下是我的代码:

查看

行动:

[HandleError(ExceptionType=typeof(Exception),View=“ApplicationError”)]
public PartialViewResult DeviceEventExpandedView(int-WidgetId,字符串工具ID)
{
var userDetail=sessionContext.UserContextBag;
int Skip=0;//对于第一页数据,传递静态值
整数取=100;
IList结果=_deviceEventClient.DeviceEventsForExpandedView(WidgetId、FacilityId、TenantId、CustomerId、UserId、this.sessionContext.UserContextBag.CultureName、Skip、Take);
返回部分视图(结果);
}
public ActionResult PageWiseData(int-WidgetId,字符串工具ID,[DataSourceRequest]DataSourceRequest请求)
{
IList Totalresult=null;
var Skip=(request.Page-1)*request.PageSize;
var Take=request.PageSize;
Totalresult=\u deviceEventClient.DeviceEventsForExpandedView(WidgetId、FacilityId、TenantId、CustomerId、UserId、this.sessionContext.UserContextBag.CultureName、Skip、Take);
返回Json(新的
{
数据=总结果,
总数=1500
});
}
问题:

首次调用“DeviceEventExpandedView”时,将加载视图 数据显示成功,但页码显示为1 只是第一次。在我的网格中,一旦我 点击filter,再次调用“PageWiseData”方法,它将拉动100 记录,这一次显示后续页面的页码。作为 每我第二次理解时,返回的数据都是JSON格式的 还包括总计=1500,但在第一种情况下,当局部视图为 已加载,未设置此计数“总计”

当加载部分视图并且第一次绑定网格时,我无法显示页码(在我的情况下应该是15页) 时间

这里有人能帮忙吗,第一次如何通过计数还是 第一次使用方法“PageWiseData”绑定网格…或任何 其他方法可以做到这一点…请帮助


如果您应用了以下内容,您不必关心或担心自己处理分页


  • 将您的
    totalResult
    变量更改为
    IQueryable

    您的
    Action
    做错了,让Kendo按照@hutchonoid的解释过滤您的结果。我认为,为此,我必须首先从数据库中提取所有记录,对吗?不对,
    。到数据源结果(请求)
    将对查询应用自己的筛选器和分页,因此只检索所需的记录。我认为,为此,我必须首先从数据库中提取所有记录,对吗???@devgal是的,只需确保它返回一个延迟的
    IQueryable
    。)但是我的存储过程需要42秒,如果我拉取所有记录,如果我通过100条记录的skip and take to过程,则需要13秒……我不想从DB本身拉取所有记录……是否可能?它不会拉取所有记录。Kendo将对查询应用其筛选器和分页,然后它将提取相关记录。@devgal Kendo将只调用您在标记中指定的方法。
    @(Html.Kendo().Grid(Model)
        .Name("expandedView_" + Model.ToArray()[0].WidgetId.ToString())
        .Columns(columns =>
        {
            columns.Bound(p => p.FacilityNameAbbreviation).Title(@Resource.FacilityName).Width("15%");
            columns.Bound(p => p.DeviceAbbreviation).Title(@Resource.DeviceName).Width("10%");
            columns.Bound(p => p.EventType).Title(@Resource.EventType).Width("40%");
            columns.Bound(p => p.SubEventCode).Title(@Resource.SubAlarmCode).Width("10%").HtmlAttributes(new { style = "text-align:right" });
            columns.Bound(p => p.FacilityEventTime).Title(@Resource.EventTime).Width("15%");
            columns.Bound(p => p.EventStatus).Title(@Resource.Status).Width("10%");
            columns.Bound(p => p.PriorityColor).Hidden(true);
        })
        .Scrollable()
        .Pageable()
        .DataSource(dt => dt
        .Ajax()
        .PageSize(100)
        .Read(read => read.Action("PageWiseData", "DeviceEvent", new { WidgetId = Model.ToArray()[0].WidgetId, FacilityIds = ViewData["Facids"].ToString() }))
        .ServerOperation(true)
        .Model(model => model.Id(p => p.FacilityEventTime)))
    )
    
    [HandleError(ExceptionType = typeof(Exception), View = "ApplicationError")]
    public PartialViewResult DeviceEventExpandedView(int WidgetId, string FacilityIds)
    {
        var userDetail = sessionContext.UserContextBag;
    
        int Skip = 0; // for first page data static value is passed
        int Take = 100;
    
        IList<AMI.WebRole.Models.Widgets.DeviceEventModel> result = _deviceEventClient.DeviceEventsForExpandedView(WidgetId, FacilityIds, TenantId, CustomerId, UserId, this.sessionContext.UserContextBag.CultureName, Skip, Take);
    
        return PartialView(result);
    }
    
    
    public ActionResult PageWiseData(int WidgetId, string FacilityIds, [DataSourceRequest]DataSourceRequest request)
    {
        IList<AMI.WebRole.Models.Widgets.DeviceEventModel> Totalresult = null;
    
        var Skip = (request.Page - 1) * request.PageSize;
        var Take = request.PageSize;
    
        Totalresult = _deviceEventClient.DeviceEventsForExpandedView(WidgetId, FacilityIds, TenantId, CustomerId, UserId, this.sessionContext.UserContextBag.CultureName, Skip, Take);
    
        return Json(new
            {
                Data = Totalresult,
                Total = 1500
            });
    }
    
    public ActionResult PageWiseData(int WidgetId, string FacilityIds, [DataSourceRequest]DataSourceRequest request)
    {
        IQueryable<AMI.WebRole.Models.Widgets.DeviceEventModel> totalresult = null;
    
        var totalresults = _deviceEventClient.DeviceEventsForExpandedView(WidgetId, 
              FacilityIds, TenantId, CustomerId, UserId,
               this.sessionContext.UserContextBag.CultureName);
    
            var results = totalresults.ToDataSourceResult(request);
            return Json(results);
    
    }