joeharrison714 / MVCGrid.Net

http://mvcgrid.net
MIT License
74 stars 55 forks source link

paging error #54

Closed MehranMazhar closed 6 years ago

MehranMazhar commented 8 years ago

when i try using paging grid by mvcgrid i get this 'There was a problem loading the grid.'

here my code MVCGridDefinitionTable.Add("PagingGrid", new MVCGridBuilder<KeyCodesBaadraan>() .WithAuthorizationType(AuthorizationType.AllowAnonymous) .AddColumns(cols => { cols.Add("Id").WithSorting(false) .WithValueExpression(p => p.KeyCodeID.ToString()); cols.Add("FirstName").WithHeaderText("First Name") .WithValueExpression(p => p.FullName); cols.Add("LastName").WithHeaderText("Last Name") .WithValueExpression(p => p.Mobile); }) .WithSorting(true, "LastName") .WithPaging(true, 10) .WithRetrieveDataMethod((context) => { var options = context.QueryOptions; var result = new QueryResult<KeyCodesBaadraan>(); using (var db = new WendaDBEntities()) { var query = db.KeyCodesBaadraan.AsQueryable(); result.TotalRecords = query.Count(); if (!String.IsNullOrWhiteSpace(options.SortColumnName)) { switch (options.SortColumnName.ToLower()) { case "firstname": query = query.OrderBy(p => p.FullName); break; case "lastname": query = query.OrderBy(p => p.Mobile); break; } } if (options.GetLimitOffset().HasValue) { query = query.Skip(options.GetLimitOffset().Value).Take(options.GetLimitRowcount().Value); } result.Items = query.ToList(); } return result; }) );

joeharrison714 commented 8 years ago

Can you try this and let me know what the error is?

Debugging Grid Errors Add the following appSetting to your web.config file to see the actual error details on grid generation instead of the custom error message:

mayank-bhuvnesh commented 8 years ago

@MehranMazhar Are you able to solve this issue?? I am also facing the same Issue.

HamidMosalla commented 7 years ago

I had the same problem, mine was not specifying the TotalRecords when the paging was enabled, as the comment in config file states:

if paging is enabled, return the total number of records of all pages.