asp.netasp.net-mvc-2mvccontrib-grid

How to incrementally load data in mvccontrib grid in Asp.Net MVC2


I have a large data set and I want to load it incrementally so the user will have faster view loading.


Solution

  • You could implement pagination (using the AsPagination extension method from the MvcContrib.Pagination namespace):

    public ActionResult Index()
    {
        IEnumerable<MyViewModel> model = ... fetch from somewhere the dataset
        return View(model.AsPagination(1, 10));
    }
    

    and in your view:

    @model IPagination<MyViewModel>
    @(Html
        .Grid<MyViewModel>(Model)
        .Columns(columns =>
        {
            columns.For(x => x.Id);
            columns.For(x => x.Name);
        })
    )
    @Html.Pager(Model)
    

    The documentation contains examples.