I have a ASP.NET MVC 4 project and a SQL View (vvItem). ItemController
MVCAppEntities db = new MVCAppEntities();
public ActionResult Index()
{
var itemqry = db.vvItem.OrderBy(s => s.name);
//var pageditems = itemqry.Skip(10).Take(20); // 25 seconds
return View(itemqry.ToList()); // 88 seconds
}
Index.cshtml View
@model IEnumerable<MVCApplication1.Models.vvItem>
@{
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),
))}
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.
Q : How can I efficiently make a view to load only the displayed records ?
I found 2 solutions : JSON version and NerdDinner
I'm not so good at JSON so I tried the NerdDinner solution. And as in my commented line
//var pageditems = itemqry.Skip(10).Take(20);
itemqry is already loaded with all the records and it took a lot of time to load.
Q2 : How can I do paging now ? I need to modify the page no. from the Index method.
public ActionResult Index(int? page, string filter1 = " ", string filter2 = " ")