This project is read-only.

How paging works?

Aug 7, 2013 at 4:58 PM
Hi. Does this grid supports correct paging&

.WithPaging(2, 10, "page")

2 - means records peer page
10 - total pages (2*10=20 records)

I do that query on request:

int totalPages;
var data = repository.GetRecords(pageNum, 2, out totalPages);

return View(new Model{Data=data, RecordsPerPage=2, TotalPages=totalPages });

Then in grid:
.WithPaging(Model.RecordsPerPage, Model.TotalPages, "page") and...


experiments show that grid expects ALL DATA. beacuse pager panel enable only you give more recors then Model.RecordsPerPage parametr.

I don't how you get 56 pages in It's seems that you take all database at once
Aug 7, 2013 at 5:12 PM

Grid.Mvc expects that you pass all your data source collection. After that grid will cut only displaying page.

If your data source is database (for example) you need to pass IQueryable<T> collection to the grid.
Grid.Mvc uses IQueryable<T> interface to construct query expressions to your data collection.
When you go to some page the grid invokes .Skip(N).Take(N) methods and when you sort data the grid invokes OrderBy or OrderByDescending methods etc.
If you pass IQueryable collection produced by ORM (like Entity Framework) - the ORM will translate query to database (SQL queries). In this case Grid.Mvc query only one page of data, that currently displayed.
If you want to see how it works, you can download the sample app code from the repository.

PS: The second parameter of WithPaging method - is a max displaying page links of the pager, not total pages. The count of the items grid retrieve automatically.
Aug 7, 2013 at 7:26 PM
Thank you for your answer.

Two question:
  1. WithPaging(2, 10, "page") for what "page" parameter need then?
  2. Please, write how Grid.Mvc released database context (ORM/Linq-To-Sql) ? Does it safe to give it IQueryable?
Please, write somewhere on the project page that it takes IQueryable as model.
Aug 8, 2013 at 4:22 AM
The project uses EF and DbSet<T> provide IQueryable<T> out of box, see SqlRepository:
        public virtual IOrderedQueryable<T> GetAll()
            return EfDbSet;
  1. "page" - is the name of query string parameter, that should be used to switch pages. try to use simple: WithPaging(2)
  2. Grid.Mvc doesn't know about the data source, that uses in the app. It uses only IQueryable collection that you provide. There is no benefits of explicitly releasing your data context. If you are using DI container you can determine PreWebRequest scope for your data context, and it will automatically dispose it after web request ends.
Feb 7, 2014 at 12:02 PM
Edited Feb 7, 2014 at 12:05 PM
Hi,i am new to Grid.Mvc project.

I am passing a ((model).(List<my own entity class>)) to the grid [(List<EntityClassName> ListName=new [List<EntityClassName>) is in the model] as follows:

@Html.Grid(Model.ListName).Columns(columns=> { columns.Add(c=>c.ColumnName1);
So on...
but i'm unable to do the paging properly.I have 9 rows in the List and i gave the size of Paging equals 5 i.e;i should get 5 records on 1st page and remaining 4 records on the 2nd page.But i m getting an empty page on click of 2,the href link as <a href="?deviceId=660&X-Requested-With=XMLHttpRequest&grid-page=2">2</a>...Actually i am selecting a deviceID based on which the the Model.ListName that i m passing to the grid will fetch the related info about that deviceID and render it on the webpage.i m getting the 1st page with 5 records but not the 2nd page.Please do post a solution if anyone is aware of the problem.
Feb 28, 2014 at 11:26 AM
Hi Bukharin,

Nice answer. But I am still having an issue of the simillar type. I have been using a Stored Procedure with Entity Framework to fetch my data.

There are thousands of records which I don't want to fetch all at a time. Also I can not use IQueryable, as the Stored Proc returns an ObjectResult.

Could you please suggest what should I do.

Mar 1, 2014 at 6:33 AM

There is no common solution for that, please see:
Mar 4, 2014 at 5:50 AM
Hi Bukharin,

Thanks for your reply. I got the solution to my problem, rather than implementing the custom pager I converted my SP to UDF accepting parameters for where clause. This solves all of my problems as the return type of a UDF in Entity Framework is IQueryable. This is because a function returns some value which makes it possible to embed in other SQL statements just like the Tables.