Search code examples
c#asp.net-mvcwebwebgrid

WebGrid paging and sorting not working


I'm using WebGrid to display my information. The problem i have with one of my page is that the paging and the sorting are not working. It works on all the other page, but on one page nothing happen.

Here is the code for the controller 

public IndiceController(IMapperFacade mapperFacade, IDonneeReferenceService<Indice> indiceService, ILogWriters logWriters)
        {
            this.indiceReference = indiceService;
            MapperFacade = mapperFacade;
        }

        public ViewResult Index(bool afficherSupprime = false)
        {
            var models = this.ApplyInitialSort(indiceReference.GetAll(!afficherSupprime));

            var viewModels = MapperFacade.GetViewModelList<Indice, IndiceViewModel>(models);
            var viewModel = new ListeViewModel<IndiceViewModel>(afficherSupprime, viewModels);
            this.ViewBag.RowsPerPage = 3;
            return View("Index", viewModel);
        }

Here is the view

@using CDP.CMG.WebUI.ViewModels.Shared
@model ListeViewModel<IndiceViewModel>
@{
    Layout = "~/Views/Shared/_ListeLayout.cshtml";
    ViewBag.Title = Layouts.Indice_Index_Title;
    ViewBag.HeaderTitle = Layouts.Indice_Index_Title;

    var grid = new WebGrid(rowsPerPage: ViewBag.RowsPerPage);
    grid.Bind(Model.ViewModels, autoSortAndPage: true, rowCount: Model.ViewModels.Count());
}

@grid.GetHtml("table table-striped table-hover",mode: WebGridPagerModes.All)


Any ideas where i'am missing something ?
Thank for the help.

Solution

  • The problem I had with the paging and the sorting , came from the partial class that was used around the WebGrid. For some reason that i can not explain the paging and sorting were not working. By removing the partial class everything is back in order.

    So my solution was to remove the partial class that was used in the code to display the WebGrid