Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET MVC Webgrid Efficient Paging
    text
    copied!<p>I have a ASP.NET MVC 4 project and a SQL View (vvItem). ItemController</p> <pre><code> MVCAppEntities db = new MVCAppEntities(); public ActionResult Index() { var itemqry = db.vvItem.OrderBy(s =&gt; s.name); //var pageditems = itemqry.Skip(10).Take(20); // 25 seconds return View(itemqry.ToList()); // 88 seconds } </code></pre> <p>Index.cshtml View</p> <pre><code>@model IEnumerable&lt;MVCApplication1.Models.vvItem&gt; @{ var norows = 20; var grid = new WebGrid(Model, canPage: true, rowsPerPage: norows); grid.Pager(WebGridPagerModes.NextPrevious); @grid.GetHtml(tableStyle: "table", headerStyle: "header", columns: grid.Columns( grid.Column(columnName: "name", header: "Name", canSort: true), grid.Column(columnName: "quantity", header: "Quantity", canSort: true), grid.Column(columnName: "code", header: "Code", canSort: true), grid.Column(columnName: "Price", header: "Price", canSort: true), ))} </code></pre> <p>In vvItem I have almost 400000 records. I thought that the webgrid Pager would load (Take()) only the displayed records and it would know to Skip() the first records if I would go to the next pages.</p> <p><strong>Q</strong> : How can I efficiently make a view to load only the displayed records ?</p> <p>I found 2 solutions : <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=618" rel="nofollow">JSON version</a> and <a href="http://nerddinnerbook.s3.amazonaws.com/Part8.htm" rel="nofollow">NerdDinner</a></p> <p>I'm not so good at JSON so I tried the NerdDinner solution. And as in my commented line <code>//var pageditems = itemqry.Skip(10).Take(20);</code> itemqry is already loaded with all the records and it took a lot of time to load.</p> <p><strong>Q2</strong> : How can I do paging now ? I need to modify the page no. from the Index method.</p> <pre><code>public ActionResult Index(int? page, string filter1 = " ", string filter2 = " ") </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload