MvcContrib.UI.Grid pagination problem

2019-08-26 22:09发布

问题:

I have an object which contains quite a few other objects in an IList called possible values. I have successfully used the mvccontrib grid plus paging before but would like to add the grid to the object’s page – hope you know what I mean. So I did something like this in my controller:

[AcceptVerbs(HttpVerbs.Get)]
public ViewResult Bla(string Id, int? page)

ViewData["PossibleValues"] = XYZ.PossibleValues.AsPagination(page ?? 1, 10);

PossibleValues definitely contains data but not ViewData["PossibleValues"]. Is this because AsPagination relies on lazy loading or something? Thanks.

Chris

回答1:

Just figured it out. Use in the controller:

ViewData["PossibleValues"] = XYZ.PossibleValues.ToList().AsQueryable().AsPagination(page ?? 1, 10);

Then in the view:

<%= Html.Grid(ViewData["PossibleValues"] as IEnumerable<FFFF>).Columns(column =>
                           {
                            column.For(gf => gf.Value).Named("Value");
                        }).Empty("Sorry no data.")%>
                       <%= Html.Pager((IPagination)(ViewData["PossibleValues"] as IEnumerable<FFFF>))%>