zoukankan      html  css  js  c++  java
  • MVCPager学习小记

    1.PageIndexParameterName怎么关联?

    答:其实就是Action里面的pageindex参数

    例子:

    @Html.Pager(Model, new PagerOptions {
        PageIndexParameterName = "pageindex", 
        ShowPageIndexBox = true, 
        PageIndexBoxType = PageIndexBoxType.DropDownList, 
        ShowGoButton = false })
    View Code

    后台:

            public ActionResult Basic(int pageindex = 1)
            {
                return View(DemoData.AllArticles.OrderByDescending(a => a.PubDate).ToPagedList(pageindex, 8));
            }
    View Code

    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 = 1 }, new { action = "CustomRouting" });
                routes.MapRoute("OptionalPaging", "{controller}/{action}/pageindex-{pageindex}", new { controller = "NoDb", action = "CustomRouting", pageindex = 1 }, new { action = "CustomRouting" });
    View Code

    前台调用:

    @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)
    View Code

    注意:如果第二个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 
        })
    View Code

    另外,如果按“下一页”,地址栏有变化,但是数据没有翻页翻过去,需要检查一下是不是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 = "120px" }) 
        <span>作者:</span>@Html.TextBoxFor(model => model.author, new { @id = "author", @name = "author", @type = "text", @style = "120px" }) 
        <span>来源:</span>@Html.TextBoxFor(model => model.source, new { @id = "source", @name = "source", @type = "text", @style = "120px" }) 
        <input type="submit" value="搜索(S)" accesskey="S" />
    }
    View Code

    还有就是,Ajax.BeginForm在这里是行不通的

    总的说来,这种方法只适合于简单的情况,还是把分页数据放到PartialView比较好

  • 相关阅读:
    hadoop完全分布式集群配置
    Hadoop启动时出现Unrecognized option: jvm的问题(收集)
    Linux下.NET开发环境构建
    Linux下常用压缩于解压缩命名收集
    Windows phone 7学习—开发工具准备
    Linux图形界面开发—monodevelop初探
    hadoop配置一定要注意hadoop所属的用户和组
    hadoop出现Incompatible namespaceIDs 的错误,导致namenode进程启动不了
    SQL不同数据库之间数据导入方法
    发送EMail电子邮件
  • 原文地址:https://www.cnblogs.com/zhengwk/p/5319250.html
Copyright © 2011-2022 走看看