相思资源网 Design By www.200059.com

JPager.Net  MVC好用的轻量级分页控件,好用到你无法想象,轻量到你无法想象。

JPager.Net  MVC好用的轻量级分页控件,实现非常简单,使用也非常简单。

JPager.Net  MVC好用的轻量级分页控件,代码精心推敲,经多人反复建议修改,最终成型使用中。非常好用分享给大家。源代码一共放出来。先上个效果图:

超好用轻量级MVC分页控件JPager.Net

JPager.Net  MVC好用的轻量级分页控件JPager.Net .dll核心代码

超好用轻量级MVC分页控件JPager.Net

PagerInBase.cs

namespace JPager.Net
{
  /// <summary>
  /// 分页基础类
  /// </summary>
  public class PagerInBase
  {
    /// <summary>
    /// 当前页
    /// </summary>
    public int PageIndex { get; set; }

    /// <summary>
    /// 页数
    /// </summary>
    public int PageSize { get; set; }

    //跳过序列中指定数量的元素
    public int Skip => (PageIndex - 1) * PageSize;

    /// <summary>
    /// 请求URL
    /// </summary>
    public string RequetUrl => System.Web.HttpContext.Current.Request.Url.OriginalString;

    /// <summary>
    /// 构造函数给当前页和页数初始化
    /// </summary>
    public PagerInBase()
    {
      if (PageIndex == 0) PageIndex = 1;
      if (PageSize == 0) PageSize = 10;
    }
  }
}

PagerResult.cs

using System;
using System.Collections.Generic;
using System.Text;

namespace JPager.Net
{
  /// <summary>
  /// ULR拼装
  /// </summary>
  internal static class Exts
  {
    public static string GetUrl(this string url, int curIndex, int reps)
    {
      return url.Replace("pageindex=" + curIndex.ToString(), "pageindex=" + reps.ToString());
    }
  }

  /// <summary>
  /// 分页核心代码
  /// </summary>
  /// <typeparam name="T"></typeparam>
  public class PagerResult<T>
  {
    public int Code { get; set; }
    public int Total { get; set; }
    public IEnumerable<T> DataList { get; set; }     
    public int PageSize { get; set; }
    public int PageIndex { get; set; }
    public string RequestUrl { get; set; }

    /// <summary>
    /// 分页页码Html
    /// </summary>
    /// <param name="cssClass">默认样式:jpager</param>
    /// <returns></returns>
    public string PagerHtml(string cssClass="jpager")
    {
      if (PageIndex == 0) PageIndex = 1;
      if (RequestUrl.IndexOf("", StringComparison.Ordinal) == -1) RequestUrl += "";
      else
      if (RequestUrl.IndexOf("&pageindex", StringComparison.Ordinal) == -1&& RequestUrl.IndexOf("", StringComparison.Ordinal) == -1) RequestUrl += "&pageindex=1";
      
      var html = new StringBuilder();
      html.AppendFormat("<span class='{0}'>", cssClass);
      var pageLen = Math.Ceiling((double)Total / PageSize);
      html.AppendFormat("<a href='{0}'> 首页 </a>", RequestUrl.GetUrl(PageIndex,1));
      html.AppendFormat("<a href='{0}'> 上页 </a>", RequestUrl.GetUrl(PageIndex, PageIndex < 2 "<a style='color:black;border:none;' href='{0}'> {1} </a>"
            : "<a href='{0}'> {1} </a>", RequestUrl.GetUrl(PageIndex, si), si++);

      html.AppendFormat("<a href='{0}'> 下页 </a>", RequestUrl.GetUrl(PageIndex, (int)(PageIndex > pageLen - 1 "<a href='{0}'> 尾页 </a>",
        Math.Abs(Total) <= 0 
        "</span>");
      return html.ToString();

    }
    
  }

}

使用方法:

HomeController.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using JPager.Net;
using JPager.Net.Web.Models;

namespace JPager.Net.Web.Controllers
{
  public class HomeController : Controller
  {
    public ActionResult Index(UserParams param)
    {

      //每页显示的条数默认10
      //param.PageSize = 10;

      //保存搜索条件
      ViewBag.SearchName = param.Name;
      ViewBag.SearchAge = param.Age;

      //获取数据集合
      var list = PageContent(); 

      //根据条件检索
      var query = param.Name!=null "Joye.net"+t.ToString(),
          Age = t + 10,
          Score = t,
          Address = "http://yinrq.cnblogs.com/",
          AddTime = DateTime.Now
        });
      }

      return list;
    }
  }
}

Models文件夹建User.cs和UserParams.cs

User.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace JPager.Net.Web.Models
{
  public class UserParams:JPager.Net.PagerInBase
  {
    public int Id { get; set; }
    public string Name { get; set; }
    public int "htmlcode">
using System;

namespace JPager.Net.Web.Models
{
  public class User
  {
    public int Id { get; set; } 
    public string Name { get; set; }
    public int Age { get; set; }
    public int Score { get; set; }
    public string Address { get; set; }
    public DateTime AddTime { get; set; }
  }
}

view显示

@model JPager.Net.PagerResult<JPager.Net.Web.Models.User>
@{
  ViewBag.Title = "Index";
}

<h2>JPager.Net MVC好用的轻量级分页控件</h2>
<div>
  <div>
    <form method="get">Name:
      <input name="Name" id="Name" />
     Age:
      <input name="Age" id="Age"/>
      <input type="submit" value="查询" />
    </form>
  </div>
  <table>
    <tr>
      <th>ID</th>
      <th>Name</th>
      <th>Age</th>
      <th>Score</th>
      <th>Address</th>
      <th>AddTime</th>
    </tr>
    @foreach (JPager.Net.Web.Models.User item in Model.DataList)
    {
      <tr>
        <td>@item.Id</td>
        <td>@item.Name</td>
        <td>@item.Age</td>
        <td>@item.Score</td>
        <td><a href="@item.Address" target="_target">@item.Address</a></td>
        <td>@item.AddTime</td>
      </tr>
    }
  </table>

</div>
<div>
  @Html.Raw(Model.PagerHtml()) 共 @Model.Total 条
</div>

<script type="text/javascript">
  //保持搜索条件
  $(function () {
    $('#Name').val('@ViewBag.SearchName');
    $('#Age').val('@ViewBag.SearchAge');
  });
</script>

github:https://github.com/decadestory/JPager.Net 

标签:
MVC分页控件,JPager.Net

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“超好用轻量级MVC分页控件JPager.Net”

暂无超好用轻量级MVC分页控件JPager.Net的评论...

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?