如何在kendo网格中使用mvc5中的部分视图分页

时间:2014-09-26 11:01:44

标签: asp.net-mvc-5 kendo-grid asp.net-mvc-partialview

我正在使用Kendo网格来显示一些用户信息。我在视图管理员中有3个选项卡,每个选项卡都是局部视图。说客户,用户,投资组合。我正在调用主视图本身时加载kendo网格,这是通过视图模型管理视图,该模型包含3个类

public class AdminViewModel
{
    public IEnumerable<CustUser> CustomerUsers { get; set; }
    public IEnumerable<Customer> Customers { get; set; }

    public IEnumerable<Portfolio> Portfolios { get; set; }
}

我将这个视图模型传递给3个局部视图中的每一个。它的工作正常,但问题是当我想进入Grid的下一页时。它只是返回页面上的Json数据。 我的剑道网格:

<div class="col-xs-12">
            @try
            {
                @(Html.Kendo().Grid(Model.CustomerUsers)
            .Name("User")
            .Columns(columns =>
                    {
                        columns.Bound(p => p.CustUserID).Visible(false);
                        columns.Bound(p => p.FirstName);
                        columns.Bound(p => p.LastName);
                        columns.Bound(p => p.CustUserName);
                        columns.Bound(p => p.EmailAddress);
                        columns.Bound(p => p.IsActive);
                        columns.Bound(p => p.ModifiedDt).Visible(false);
                        columns.Bound(p => p.CreatedDt).Visible(false);
                        columns.Command(command =>
                        {
                            //command.Edit();
                            //command.Destroy().Text("Del");
                            command.Custom("Delete").Click("ConfirmDeleteUnit").Text("<span class='fa fa-trash-o'></span>").HtmlAttributes(new { @style = "width:40px !important;min-width:0px !important;" }); ;
                        }).Width(160);
                    })
               .Pageable()
    .Sortable()
    .Scrollable(scrollable => scrollable.Virtual(true))
            .DataSource(dataSource => dataSource
                .Ajax()

                        .PageSize(25)
                            .Events(events => events.Error("error_handler"))
                        .Model(model =>
                            {
                                model.Id(i => i.CustUserID);

                            })

                                .Read(read => read.Action("LazyCustUser_Read", "Admin")
                                )
                    //.Update(update => update.Action("InlineEditUnit_Update", "Unit"))
                    //.Destroy(update => update.Action("InlineEditUnit_Destroy", "Unit"))
             )
                )
            }
            catch (Exception exe)
            {

                CSP.Web.Helpers.Log objLog = new CSP.Web.Helpers.Log();
                objLog.LogError(exe.Message.ToString() + this.ToString());
            }
        </div>

和我的管理控制器

 public async Task<ActionResult> Index()
    {


        if (Session["custUserID"] != null)
        {
            try
            {
                var custUsers = await _custUserRepo.GetAllCustUsers();
                var customers = await _CustomerRepo.GetAllCustomers();
                var portfolios = await _portfolioRepo.GetPortFolios();
                if (custUsers == null)
                    return RedirectToAction("ShowError", "Error");
                adminViewModel.CustomerUsers = custUsers;
            }
            catch (Exception exe)
            {
                objError.LogError(exe.Message);
                return RedirectToAction("ShowError", "Error");
            }
            return View(adminViewModel);
        }
        else
        {

            return RedirectToAction("Index", "Account");
        }
    }


public async Task<ActionResult> LazyCustUser_Read([DataSourceRequest] DataSourceRequest request)
    {
        if (Session["custUserID"] != null)
        {
            try
            {
                var custUser = await _custUserRepo.GetAllCustUsers();
                return Json(custUser.ToDataSourceResult(request), JsonRequestBehavior.AllowGet);
            }
            catch (Exception exe)
            {
                Log objLog = new Log();
                objLog.LogError(exe.InnerException.ToString());
                return RedirectToAction("ShowError", "Error");
            }
        }
        else
        {
            return RedirectToAction("Index", "Account");
        }

    }

0 个答案:

没有答案