bootstrap 的paginator组件怎么用啊,我前台jquery代码如下,控制器里怎么接受page啊

qq_41008959 2017-12-07 03:07:00
$(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);


}


}

不会写控制器,乱写的。请大家看看应该怎么写。我的写法分页点击页码没用。
...全文
129 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
webdiyer 2017-12-08
  • 打赏
  • 举报
回复
Mvc分页建议试试MvcPager分页控件,更简单方便 : http://www.webdiyer.com/mvcpager/

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧