MVC3分頁查詢

//我這裏拿學生信息來做範例
 
 
@model IEnumerable< 程序集.Models.Student>//指定數據模型
 
 
@{
    //設置每頁顯示的信息條數和指定數據源
    var grid = new WebGrid(source: Model, rowsPerPage: 2, canPage: true, canSort: true);
}
 
 
@grid.GetHtml(
        columns: grid.Columns
        (
            //指定每列顯示的標題
            grid.Column("StudentId", "學生編號", style: "mynameStyle"),
            grid.Column("StudentName", "學生姓名", style: "mynameStyle"),
            grid.Column("StudentAge", "學生年齡", style: "mynameStyle"),
            grid.Column("StudentSex", "學生性別", style: "mynameStyle"),
            grid.Column("Grade.GradeName", "學生班級", style: "mynameStyle"),
 
            grid.Column("", "", format: @<text> @Html.ActionLink("編輯", "Edit", new { Id = item.StudentId })|
                @Html.ActionLink("詳細", "Details", new { id = item.StudentId })|
                @Html.ActionLink("刪除", "Delete", new { id = item.StudentId })</text>)
         ), tableStyle: "grid", headerStyle: "headerStyle1", selectedRowStyle: "selectedRowStyle",
                                      displayHeader: !IsPost,
                                      fillEmptyRows: !IsPost, emptyRowCellValue: "這行沒東西",
                                      mode: WebGridPagerModes.All, firstText: "第一頁",
                                      previousText: "上一頁", nextText: "下一頁", lastText: "最後一頁",
                                    numericLinksCount: 15
    )
    <p>總頁數:@grid.PageCount | 每頁:@grid.RowsPerPage 行 | 當前第:@(grid.PageIndex+1) 頁</p>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章