zoukankan      html  css  js  c++  java
  • AJAX分页带页码

    ///视图

    GoToPage(1, "pageHtml")
    function GoToPage(pageindex, pageHtml) {
    $.ajax({
    url: "/fenye/index",
    type: "post",
    data: { pageindex: pageindex },
    success: function (data) {
    var str = "";
    for (var i = 0; i < data.Titemlist.length; i++) {
    str += " <tr>";
    str += " <td>" + data.Titemlist[i].Id + "</td>";
    str += " <td>" + data.Titemlist[i].Name + "</td>";
    str += " <td>" + data.Titemlist[i].Leixing + "</td>";
    str += " <td>" + data.Titemlist[i].Feiyong + "</td>";
    str += " <td>" + data.Titemlist[i].Shoufeiren + "</td>";
    str += " <td>" + new Date(parseInt(data.Titemlist[i].shijian.replace(/D/img, ""))).toLocaleDateString() + "</td>";
    str += " </tr>";
    }
    $("#tfoot1").html(str);
    GetpageHtml(data.totapage, pageindex, pageHtml)
    }
    })
    }

    ///控制器

    public ActionResult Index(int pageindex)
    {
    var result = new BLL.wuyebll().show(pageindex, 6);
    return Json(result);
    }

    ///wcf

    /// <summary>
    /// 万能分页
    /// </summary>
    /// <param name="pageindex"></param>
    /// <param name="pagesize"></param>
    /// <returns></returns>
    public wuyeinfo<wuyemodel> show(int pageindex,int pagesize)
    {
    SqlCommand cmd = new SqlCommand("fenye",con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.AddWithValue("@pagesize",pagesize);
    cmd.Parameters.AddWithValue("@pageindex", pageindex);
    cmd.Parameters.AddWithValue("@pagecount",SqlDbType.Int);
    cmd.Parameters["@pagecount"].Direction = ParameterDirection.Output;
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable de = new DataTable();
    da.Fill(de);
    var totalcount = Convert.ToInt32(cmd.Parameters["@pagecount"].Value);//把存储过程里的count总条数强行转化为int类型
    var ds = JsonConvert.SerializeObject(de);
    var result = JsonConvert.DeserializeObject<List<wuyemodel>>(ds);
    wuyeinfo<wuyemodel> list = new wuyeinfo<wuyemodel>();
    list.Titemlist = result;
    list.pagesize = pagesize;
    list.pageindex = pageindex;
    if(totalcount%pagesize==0)
    {
    list.totapage = totalcount / pagesize;
    }
    else
    {
    list.totapage = totalcount / pagesize + 1;
    }
    return list;
    }

    ///model类

    public class wuyeinfo<T>
    {
    public int pageindex { get; set; }
    public int pagesize { get; set; }
    public int totapage { get; set; }
    public List<T> Titemlist { get; set; }
    }
    public class wuyemodel
    {
    public int Id{get;set;}
    public string Name{get;set;}
    public string Leixing{get;set;}
    public int Feiyong{get;set;}
    public string Shoufeiren{get;set;}
    public DateTime shijian{get;set;}
    }

  • 相关阅读:
    使用c#生成Identicon图片
    C#实现对文件目录的实时监控
    .Net Core的一些个人总结
    天天写业务代码,如何成为「技术大牛」?
    两款工作流JBPM和CCBPM的对比
    MVC5+EasyUI+EF6+Linq通用权限系统出炉--登录(2)
    MVC5+EasyUI+EF6+Linq通用权限系统出炉(1)
    博客园,久违了
    VS2010 代码行数统计以及代码复制汉字出现乱码
    关于TerrainExplorer的一些资源网址设置方法(备忘)
  • 原文地址:https://www.cnblogs.com/htbmvc/p/7880818.html
Copyright © 2011-2022 走看看