0

这曾经工作......但现在 PagedListPager 的 >> 锚标记总是将 null 传递给控制器​​以获得所需的页面值......

VS 2013 Web Express 和 MVC 4,为所有人提供最新的软件包更新。

就像在 Scot Allen 的 MVC 4 介绍中一样,我有一个 PagedListPager 的部分视图

控制器:

    public ActionResult Catalog(string Id= "0", int page=1)
    {

          var CurrentItemsPage = (get-data-blaw-blaw-blaw).ToPagedList(page,18);

          var model = new ShowRoomCatalogPackage(){ CurrentItems = CurrentItemsPage};

          return View(model);
    }

目录页面

@model craftstore.Models.ShowRoomCatalogPackage

@{
ViewBag.Title = "Catalog";
Layout = "~/Views/Shared/_Details.cshtml";
}

@using (Ajax.BeginForm("Catalog", "Home", new { category = @Model.SelectedCategoryId, page = 1 },
                new AjaxOptions
                    {
                        UpdateTargetId = "products",
                        InsertionMode = InsertionMode.Replace,
                        HttpMethod = "post"
                    }
            )
        )
{
<div class="container" >
    <div class="row">
            <div class="col-lg-10 col-md-5 col-sm-4 dropdown-menu">
                @Html.LabelFor(m => m.SelectedCategoryId)
                @Html.DropDownList("id", Model.CategoryItems, new { @id = "ddlCategories", onchange = "this.form.submit();" })
            </div>
            <div class="col-lg-2 col-md-2 col-sm-1">
            @Html.ActionLink("Your Cart", "Index", "ShoppingCart", "", new { @class = "btn btn-green btn-lg" })
        </div>
    </div>
    <div class="row">
        @Html.Partial("_CatalogPartial", Model.CurrentItems)
    </div><!-- row -->
</div><!-- container -->
}
<br />
<br />

@section Scripts
{
    <script type="text/javascript">
        new AnimOnScroll(document.getElementById('grid'), {
            minDuration: 0.4,
            maxDuration: 0.7,
            viewportFactor: 0.2
        });
    </script>
}

部分观点:

@model IPagedList<ShowroomCatalog>

<div id="productList">
<div class="col-lg-12 col-md-12 col-sm-12">
    <div class="pagedList" data-cs-target="#productList">
        @Html.PagedListPager(Model, page => Url.Action("Index", new { category = ViewBag.SelectedCategoryId, page }), PagedListRenderOptions.MinimalWithItemCountText)
    </div>
    <ul class="grid effect-2" id="grid">
        @foreach(var item in Model)
        {
            var path = String.Format("~/Content/Images/catalog/{0}/{1}", item.OfferType, item.ImagePath);
            <li>
                <div class="itembox">
                    <div class="imagebox">
                        <a href="@Url.Action("Detail", "Home", new { id = item.Id })" title="Detail for @item.CatalogName">
                            <img class="catalogimg" src="@Url.Content(path)" />
                        </a>
                    </div>
                    <p>@item.CatalogName</p>
                </div>
            </li>
        }
    </ul>
</div>
</div><!-- productlist -->

现在浏览器中渲染的局部视图在锚点中没有任何可能正常或不正常的东西......

    <div class="pagedList" data-cs-target="#productList">
            <div class="pagination-container"><ul class="pagination"><li class="disabled PagedList-skipToPrevious"><a rel="prev">«</a></li><li class="disabled PagedList-pageCountAndLocation"><a>Showing items 1 through 18 of 65.</a></li><li class="PagedList-skipToNext"><a href="" rel="next">»</a></li></ul></div>
    </div>

当您将鼠标悬停在 >> 上时,它不会在 URL 中显示 page 参数:

将鼠标悬停在分页控件上以向前翻页

再次,回到控制器 - 我得到类别 (15) 但没有页面参数或 Request.URL 参数传递给控制器​​ - 由于一些路由错误,它没有隐藏......我想......

如何让分页控件再次工作......???

[编辑:还有一点注意 - 寻呼机上的 url 路径是 /controller/action/category/page 而不是 Scot Allen 的 OdeToFood 示例中显示的内容,它的等价物是 /controller/action/category?page=n (如 /主页/目录/15?page=1 ]

4

1 回答 1

0

我错过了 PagedList 类锚元素的 JS。

   var getPage = function () {
    var $a = $(this);

    var options = {
        url: $a.attr("href"),
        data: $("form").serialize(),
        type: "get"
    };

    $.ajax(options).done(function (data) {
        var target = $a.parents("div.pagedList").attr("data-otf-target");
        $(target).replaceWith(data);
    });
    return false;

};

这被解雇了:

$(".main-content").on("click", ".pagedList a", getPage);

但是,这意味着您需要在您的 _Layout.cshtml 文件中将您的 @RenderBody() 调用包装在具有主要内容类的东西中。一个例子:

        <section class="content-wrapper main-content clear-fix">
            @RenderBody()
        </section>
于 2014-04-04T13:12:01.913 回答