bootstrap 的paginator组件怎么用啊,我前台jquery代码如下,控制器里怎么接受page啊
$(function ()
{
var options = {
currentPage: 1,
totalPages: $('#totalpage').val(),
numberofpages: 2,
itemTexts: function (type, page, current) {
switch (type) {
case "first":
return "首页";
case "prev":
return "上一页";
case "next":
return "下一页";
case "last":
return "末页";
case "page":
return page;
}
}, onPageClicked: function (event,originalEvent,type,page) {
var json = { page: page };
var jsonStr=JSON.stringify(json);
$.ajax({
url: "Book/List",
type:"post",
data:jsonStr,
success: function (data)
{
$('#logtable').html(data);
}
});
},
};
$('#example').bootstrapPaginator(options);
});
HTML
<div id="logtable">
<table id="table" class="table">
<thead>
<tr>
<th>操作</th>
<th>ID</th>
<th>BookName</th>
<th>BookType</th>
<th>Author </th>
<th>PubData</th>
<th>PubTime</th>
<th>删除</th>
<th>编辑</th>
<th>添加</th>
</tr>
</thead>
<tbody>
@if (Model.Count!=0)
{
foreach (var item in Model)
{
<tr>
<th>@Html.CheckBox("chk",false)</th>
<th>@item.ID</th>
<th>@item.BookName</th>
<th>@item.BookType.BookTypeName</th>
<th>@item.Author</th>
<th>@item.PubData</th>
<th>@item.PubTime</th>
<th>@Html.ActionLink("删除", "DeleteById", new{ id=item.ID }, new { onclick="return confirm('确认删除吗')" })</th>
<th>@Html.ActionLink("编辑", "UpdateBookById", new { id = item.ID }, new { onclick="return confirm('确认编辑吗')" })</th>
<th>@Html.ActionLink("添加", "Add", new { onclick="return confirm('确认添加吗')" })</th>
</tr>
}
}
</tbody>
</table>
请输入课程名字关键字: <input id="val" type="text" /><input type="button" value="查询" id="btn_Find" />
<input id="btn" type="button" value="批量删除" />
</div>
<div id="example"></div>
<input type="hidden" id="totalpage" value="@ViewBag.TotalPage" />
控制器
public ActionResult List(int? page,int take=2)
{
using (EFDbCotext dbcontext=new EFDbCotext())
{
if (page.HasValue)
{
var sr = new StreamReader(Request.InputStream);
var str = sr.ReadToEnd();
page = Convert.ToInt32(sr.ReadToEnd());
}
else
{
page = 1;
}
var model = BookService.GetAllBook();
int count = PageDive.GetAllBookCount();
int totalPage = count / take;
ViewBag.TotalPage = totalPage;
var data = model.Skip(take * ((int)page - 1)).Take(take).ToList();
return View(data);
}
}
不会写控制器,乱写的。请大家看看应该怎么写。我的写法分页点击页码没用。
{
var options = {
currentPage: 1,
totalPages: $('#totalpage').val(),
numberofpages: 2,
itemTexts: function (type, page, current) {
switch (type) {
case "first":
return "首页";
case "prev":
return "上一页";
case "next":
return "下一页";
case "last":
return "末页";
case "page":
return page;
}
}, onPageClicked: function (event,originalEvent,type,page) {
var json = { page: page };
var jsonStr=JSON.stringify(json);
$.ajax({
url: "Book/List",
type:"post",
data:jsonStr,
success: function (data)
{
$('#logtable').html(data);
}
});
},
};
$('#example').bootstrapPaginator(options);
});
HTML
<div id="logtable">
<table id="table" class="table">
<thead>
<tr>
<th>操作</th>
<th>ID</th>
<th>BookName</th>
<th>BookType</th>
<th>Author </th>
<th>PubData</th>
<th>PubTime</th>
<th>删除</th>
<th>编辑</th>
<th>添加</th>
</tr>
</thead>
<tbody>
@if (Model.Count!=0)
{
foreach (var item in Model)
{
<tr>
<th>@Html.CheckBox("chk",false)</th>
<th>@item.ID</th>
<th>@item.BookName</th>
<th>@item.BookType.BookTypeName</th>
<th>@item.Author</th>
<th>@item.PubData</th>
<th>@item.PubTime</th>
<th>@Html.ActionLink("删除", "DeleteById", new{ id=item.ID }, new { onclick="return confirm('确认删除吗')" })</th>
<th>@Html.ActionLink("编辑", "UpdateBookById", new { id = item.ID }, new { onclick="return confirm('确认编辑吗')" })</th>
<th>@Html.ActionLink("添加", "Add", new { onclick="return confirm('确认添加吗')" })</th>
</tr>
}
}
</tbody>
</table>
请输入课程名字关键字: <input id="val" type="text" /><input type="button" value="查询" id="btn_Find" />
<input id="btn" type="button" value="批量删除" />
</div>
<div id="example"></div>
<input type="hidden" id="totalpage" value="@ViewBag.TotalPage" />
控制器
public ActionResult List(int? page,int take=2)
{
using (EFDbCotext dbcontext=new EFDbCotext())
{
if (page.HasValue)
{
var sr = new StreamReader(Request.InputStream);
var str = sr.ReadToEnd();
page = Convert.ToInt32(sr.ReadToEnd());
}
else
{
page = 1;
}
var model = BookService.GetAllBook();
int count = PageDive.GetAllBookCount();
int totalPage = count / take;
ViewBag.TotalPage = totalPage;
var data = model.Skip(take * ((int)page - 1)).Take(take).ToList();
return View(data);
}
}
不会写控制器,乱写的。请大家看看应该怎么写。我的写法分页点击页码没用。
...全文
相关推荐
bootstrap paginator分页前后台用法示例
主要为大家详细介绍了bootstrap paginator分页前后台用法示例,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
bootstrap paginator分页插件的两种使用方式实例详解
Bootstrap Paginator是一款基于Bootstrap的js分页插件,下面通过本文给大家介绍bootstrap paginator分页插件的两种使用方式,一起看看吧
Bootstrap Paginator分页插件与ajax相结合实现动态无刷新分页效果
主要介绍了Bootstrap Paginator分页插件与ajax相结合实现动态无刷新分页效果,非常不错,具有参考借鉴价值,感兴趣的朋友一起看下吧
bootstrap-paginator.rar
压缩包中包换使用bootstrap-paginator进行前端分页所需要的CSS和JS,包括jquery相关、bootstrap相关的JS和CSS
Bootstrap Paginator分页插件使用方法详解
主要为大家详细介绍了Bootstrap Paginator分页插件使用方法,具有一定的实用性,感兴趣的小伙伴们可以参考一下


