WebGrid分页无法正常工作

时间:2018-05-31 07:39:56

标签: c# asp.net-mvc webgrid

我有一个下拉按钮和按钮控件,按钮点击我绑定WebGrid,这工作正常,在加载网格上将为空,但绑定后网格分页不起作用,下面是我的代码

@using (Html.BeginForm("EmpLog", "Labels", FormMethod.Post))
{
  @Html.DropDownListFor(x => x.SelectedValue, Model.Values, "----Select----", new { id = "ddlName", @class = "form-control col-md-6" })
  <input type="submit" value="Search" id="btnSearch" class="btn btn-default" />

  @{
     var gridview = new WebGrid(source: Model.LstLog, rowsPerPage: 20, ajaxUpdateContainerId: "grid", canSort: false);
   }

  @if (Model.Lst != null)
   {
     @gridview.GetHtml(
                  htmlAttributes: new { id = "gridlogs" },
                  fillEmptyRows: false,
                  alternatingRowStyle: "alternate-row",
                  headerStyle: "grid-header",
                  footerStyle: "grid-footer",
                  selectedRowStyle: "grid-selected-row",
                  rowStyle: "grid-row-style",
                  mode: WebGridPagerModes.All,
                  firstText: "<< First",
                  previousText: "< Prev",
                  nextText: "Next >",
                  lastText: "Last >>",
                  columns: new[] {
                  gridview.Column("View", header: null, style: "click_able", format: @<text><a href="javascript:ViewFullDetails('@item.Id');">View</a></text>, canSort: false),
                  gridview.Column("JoinDate",header: "Join Date"),
                  gridview.Column("DeptName",header: "Dept Name"),
                  gridview.Column("Project",header: "Project")
                 }
             )}
    }

    [HttpGet]
    public ActionResult EmpLog()
    {
         model.Values = GetDDLInfo();
         return View();
    }

    [HttpPost]
    public ActionResult EmpLog()
    {
         model.Values = GetDDLInfo();
         model.LstLog= GetLogInfo();
         return View(model);
    }

我对WebGrid不够好,请帮助我应用分页。

1 个答案:

答案 0 :(得分:1)

我已添加以下代码来处理分页

$('th a, tfoot a').click(function () {
    $('form').attr('action', $(this).attr('href')).submit();
    return false;
});