ASP. NET MVC paging problem resolution

  • 2021-09-12 00:48:22
  • OfStack

When using Ajax. Pager for paging, you should pay attention to the following aspects:

1, 1 must introduce js; jquery. unobtrusive-ajax. min. js;

2, 1 Be sure to use the registration pager on the page by @ {Html. RegisterMvcPagerScriptResource ();} ;

Specific usage examples:


<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"> Jump </button></span>
    </div>
  </div>
</div>

Where Model is an IpagedList object, the method for obtaining PagerOptions is as follows:


/// <summary>
    ///  Page turning configuration item 
    /// </summary>
    /// <returns></returns>
    public PagerOptions GetPagerOption()
    {
      PagerOptions options = new PagerOptions
      {
        AutoHide = false,
        FirstPageText = " Home page ",
        LastPageText = " End page ",
        NextPageText = " Under 1 Page ",
        PrevPageText = " Upper 1 Page ",
        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;
    }

As far as we know, this control does not support displaying the total number of records and the total number of pages.


Related articles: