ASP.NET MVC分页 ASP.NET MVC分页问题解决

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

ASP.NET MVC分页 ASP.NET MVC分页问题解决

wangwust   2021-03-24 我要评论
想了解ASP.NET MVC分页问题解决的相关内容吗,wangwust在本文为您仔细讲解ASP.NET MVC分页的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:ASP.NET,MVC,分页,下面大家一起来学习吧。

在使用Ajax.Pager进行分页的时候需要注意一下几个方面:

  1、一定要引入jquery.unobtrusive-ajax.min.js这个js;

  2、一定要在页面中使用注册分页器,注册方法:@{Html.RegisterMvcPagerScriptResource();};

具体的使用方法示例:

<div class="row" style="position: relative; left: 30%">
  <div class="col-md-8" style="width: auto">
    @{
      PagerConfig pagerConfig = new PagerConfig("pageIndex", "pageIndexBox", "goToBtn");
      PagerOptions options = pagerConfig.GetPagerOption();
    }
    @Ajax.Pager(Model, options).AjaxOptions(a => a.SetUpdateTargetId("articles").SetHttpMethod("Post").SetDataFormId("searchView"))
  </div>
  <div class="col-md-4">
    <div class="input-group" style="width: 120px; margin: 20px 0">
      <input type="text" id="pageIndexBox" class="form-control" />
      <span class="input-group-btn"><button class="btn btn-primary" id="goToBtn">跳转</button></span>
    </div>
  </div>
</div>

其中Model是IpagedList对象,获取PagerOptions的方法如下:

/// <summary>
    /// 翻页配置项
    /// </summary>
    /// <returns></returns>
    public PagerOptions GetPagerOption()
    {
      PagerOptions options = new PagerOptions
      {
        AutoHide = false,
        FirstPageText = "首页",
        LastPageText = "尾页",
        NextPageText = "下一页",
        PrevPageText = "上一页",
        PageIndexParameterName = this._pageIndexParaName,
        ContainerTagName = "ul",
        CssClass = "pagination",
        CurrentPagerItemTemplate = "<li class=\"active\"><a href=\"#\">{0}</a></li>",
        DisabledPagerItemTemplate = "<li class=\"disabled\"><a>{0}</a></li>",
        PagerItemTemplate = "<li>{0}</li>",
        PageIndexBoxId = this._pageIndexBoxId,
        GoToButtonId = this._goToButtonId,
        NumericPagerItemCount = 5
      };

      return options;
    }

目前所知,该控件不支持显示记录总数及总页数。

猜您喜欢

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们