AJAX分页带页码
Posted htb
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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;}
}
以上是关于AJAX分页带页码的主要内容,如果未能解决你的问题,请参考以下文章
ajax查询后如何更新knppaginatorbundle的分页模板