正在显示启用了分页器但显示所有记录而不分页的网格。也显示寻呼机。RegisterGrid() 方法的代码如下:-
public static void RegisterGrids()
{
GridDefaults defaultSet1 = new GridDefaults()
{
Paging = true,
ItemsPerPage = 5,
NoResultsMessage = "Sorry, no results were found"
};
MVCGridDefinitionTable.Add("grdFiles", new MVCGridBuilder<FilesModel>(defaultSet1)
.WithAuthorizationType(AuthorizationType.AllowAnonymous)
.AddColumns(cols =>
{
cols.Add("FileName")
.WithValueExpression(p => p.Name.ToString());
cols.Add("LastModified").WithHeaderText("LastModified")
.WithValueExpression(p => p.LastModified.ToString());
cols.Add("Size").WithHeaderText("Size")
.WithValueExpression(p => p.Size.ToString());
})
.WithRetrieveDataMethod((context) =>
{
var res = DisplayFiles();
return new QueryResult<FilesModel>()
{
Items = res,
TotalRecords = res.Count // if paging is enabled, return the total number of records of all pages
};
})
);
}
查看代码是:
@model IEnumerable<FileViewerWeb.Models.FilesModel>
@using MVCGrid.Web;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div class="well well-lg" style="padding-top:10px">
<h2>Explore Uploaded Files</h2>
</div>
@Html.MVCGrid("grdFiles")
控制器代码:-
public ActionResult Index()
{
return View();
}