Precautions for using mvcpager paging control

Time:2021-9-7

Learning MVC for the first time, I made a single page application, which needs to display multiple pages without refresh and update.

Found the mvcpager control, very easy to use, and encountered many problems in the process of using Ajax. Slowly debug and consult Mr. Yang (author of mvcpaegr), and Yu has solved it.

First, nuget package is added. Search mvcpager to find.

Controller side must reference

using Webdiyer.WebControls.Mvc;

There are not many records on the back end. I can almost understand it from the official demo. It mainly records the front end.

<div>
  @Ajax.Pager(Model, new PagerOptions
 {
  Showfirstlast = false, // displays the first page button
  Showprevnext = false, // display the last page button
  Numericpageritemcount = 5, // maximum number of pages displayed
  Pageindexparametername = "page", // the paging parameter passed to the backend. If there are multiple pages on the same page, this parameter must be different
  Id = "callajax", // the ID of the paging control. You need to refresh the page after modifying the content.
  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>"
 },
 new MvcAjaxOptions { UpdateTargetId = "calllogpage",EnableHistorySupport = false })
 </div>

Then add it where you need to refresh the paging control after execution. If you add or delete it, execute it

Webdiyer.MvcPagers.getById("callajax").ajaxReload();// The ID here is the ID specified by the paging control

Important. To use the above method, you need to add a method in the jQuery plug-in of mvcpager.js


ajaxReload:function(){
  var context = this;
  context.allowReload = true;
  context.allowCache=false;
  var index = context.__getPageIndex(context.pageIndexName);
  context.__ajax(index===0?1:index, { type: this.httpMethod, data: [] });
 },

Important, after modifying mvcpager.js, you can’t use mvcpager’s JS script to register methods.

Just reference mvcpager.js directly.

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support developpaer.

Recommended Today

Beautify your code VB (VBS) code formatting implementation code

However, vb.net does have many new functions that VB6 does not have. The automatic typesetting of code is one, which is the function we want to realize today – VB code formatting.Let’s look at the effect: Before formatting: Copy codeThe code is as follows: For i = 0 To WebBrowser1.Document.All.length – 1 If WebBrowser1.Document.All(i).tagName = […]