后台方法
using (SqlConnection conn = new SqlConnection(str))
{
string sql = $"select * from Goods where 1 = 1";
if (!string.IsNullOrWhiteSpace(name))
{
sql += $"and Name like ‘%{name}%‘";
}
var list = conn.Query<ModelInfo>(sql);
Pages pag = new Pages();
pag.ModelInfos = list.OrderBy(x => x.ID)
.Skip((index - 1) * size)
.Take(size).ToList();
var count = list.Count();
pag.Page = count / size + (count % size == 0 ? 0 : 1);
return pag;
}
public class Pages
{
public List<类名> 类别名{ get; set; }
public int Page { get; set; }
}
前台代码
<div>
<input id="Button1" onclick="first()" type="button" value="首页" />
<input id="Button1" onclick="prev()" type="button" value="上一页" />
<input id="Button1" onclick="next()" type="button" value="下一页" />
<input id="Button1" onclick="last()" type="button" value="尾页" />
</div>
<script>
var index1 = "";
var pagecount = "";
function first() {
index1 = 1;
log(index1);
}
function prev() {
index1--;
if (index1 == 0) {
index1 = 1;
}
log(index1);
}
function next() {
index1++;
if (index1 > pagecount) {
index1 = pagecount;
}
log(index1);
}
function last() {
log(pagecount);
}
</script>