MVCPager学习小记
2024-08-29 23:37:38
1.PageIndexParameterName怎么关联?
答:其实就是Action里面的pageindex参数
例子:
@Html.Pager(Model, new PagerOptions {
PageIndexParameterName = "pageindex",
ShowPageIndexBox = true,
PageIndexBoxType = PageIndexBoxType.DropDownList,
ShowGoButton = false })
后台:
public ActionResult Basic(int pageindex = )
{
return View(DemoData.AllArticles.OrderByDescending(a => a.PubDate).ToPagedList(pageindex, ));
}
2.输入页码无法跳转是怎么回事?
需要添加如下引用:
<script type="text/javascript" src="/Scripts/jquery-1.8.2.min.js"></script>
并通过如下方式注册MvcPager的客户端jQuery插件脚本:
@section Scripts{@{Html.RegisterMvcPagerScriptResource();}}
3.以下各节已定义,但尚未为布局页“~/Views/Shared/_Layout.cshtml”呈现:“Scripts”
嵌套的顶层应该写:
@RenderSection("Scripts", false)
误写成了:
@section Scripts{
@RenderSection("Scripts",false)
}
4.有关自定义路由
路由设置成这样:
routes.MapRoute("Paging", "{controller}/{action}/page_{pageindex}", new { controller = "NoDb", action = "CustomRouting", pageindex = }, new { action = "CustomRouting" });
routes.MapRoute("OptionalPaging", "{controller}/{action}/pageindex-{pageindex}", new { controller = "NoDb", action = "CustomRouting", pageindex = }, new { action = "CustomRouting" });
前台调用:
@Html.Pager(Model, new PagerOptions { ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.DropDownList, ShowGoButton = false, FirstPageRouteName = "Default" }, "Paging")
@Html.Pager(Model, new PagerOptions { ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.DropDownList, ShowGoButton = false, FirstPageRouteName = "Default" }, "OptionalPaging", null)
注意:如果第二个pager没有设置最后一个参数(routeValues)为null,则两个pager产生的路由信息完全相同,因为MVC中匹配到了第一个路由就把后面那个忽略了。
5.有关Ajax局部加载(不用PartialView的情况)
需要把EnablePartialLoading设为true,如:
@Ajax.Pager(Model,
new PagerOptions {
PageIndexParameterName = "id",
ShowPageIndexBox = true,
PageIndexBoxType = PageIndexBoxType.DropDownList,
ShowGoButton = false
},
new MvcAjaxOptions {
UpdateTargetId = "articles",
EnablePartialLoading = true
})
另外,如果按“下一页”,地址栏有变化,但是数据没有翻页翻过去,需要检查一下是不是BeginForm忘了加:
@Html.BeginForm()
复杂一点的:
@using (Html.BeginForm("AjaxPaging", "NoDb", new { id = "" }, FormMethod.Get, new { id = "searchForm" }))
{
<span>标题:</span>@Html.TextBoxFor(model => model.title, new { @id = "title", @name = "title", @type = "text", @style = "width:120px" })
<span>作者:</span>@Html.TextBoxFor(model => model.author, new { @id = "author", @name = "author", @type = "text", @style = "width:120px" })
<span>来源:</span>@Html.TextBoxFor(model => model.source, new { @id = "source", @name = "source", @type = "text", @style = "width:120px" })
<input type="submit" value="搜索(S)" accesskey="S" />
}
还有就是,Ajax.BeginForm在这里是行不通的
总的说来,这种方法只适合于简单的情况,还是把分页数据放到PartialView比较好
最新文章
- [转]Linux中configure/makefile
- authorization与URL授权
- Java04
- windows server 2008 配置安装AD 域控制器
- JS中delete删除对象属性
- 基于Solr实现HBase的二级索引
- 【C语言】10-字符和字符串常用处理函数
- NBOJv2 Problem 1009 蛤玮的魔法(二分)
- C++中new和delete来创建和释放动态数组
- 【锋利的JQuery-学习笔记】菜单栏及其2级菜单
- VS中批量删除cs代码中的#region和#endregion
- Trapping Raining Water 解答
- SolrCloud今日大纲
- IDEA+Maven配置MyBatis的初体验(坑点总结)
- 这是一个蒟蒻的计划……QAQ
- Jenkins结合.net平台综合之完整示例项目
- 【微服务目录】.NET Core 微服务介绍
- ceph存储集群测试方案
- POST数据中有特殊符号导致数据丢失的解决方法
- C# 编码标准(二)