【问题标题】:How to keep URL's parameters with Html.PagedListPager如何使用 Html.PagedListPager 保留 URL 的参数
【发布时间】:2018-02-10 20:31:44
【问题描述】:

我是新的 Html.PagedListPager 并试图在我的项目中使用它。这似乎很有用,但我有一个问题要解决。

当我使用下面的代码时,一切都按预期工作。但是,当我单击具有以下代码的页码之一时,它会清除所有 URL 参数。

@Html.PagedListPager(Model, Page=> Url.Action("Products", new { Page,  sortOrder = ViewBag.CurrentSort, currentFilter = ViewBag.CurrentFilter }), PagedListRenderOptions.ClassicPlusFirstAndLast)

当我点击其中一个页面时,我会丢失 URL 中的类别和品牌值

http://localhost:53307/Home/Products?Page=2&Category=Steel&Brand=BMW

此网址更改为

http://localhost:53307/Home/Products?Page=2

如何保持品牌和类别的价值?提前致谢

【问题讨论】:

  • 您的代码中没有与CategoryBrand 相关的任何内容 - 您添加的唯一参数是sortOrdercurrentFilter

标签: asp.net .net asp.net-mvc razor


【解决方案1】:
@Html.PagedListPager(Model, page => Url.Action("Products",
                            new { page, sortOrder = ViewBag.CurrentSort,  Category = ViewBag.Category, Brand = ViewBag.Brand }))

在控制器动作中:

 public ActionResult Products(string SortOrder, string Category,sting Brand, int? Page)
{
            ViewBag.CurrentSort = SortOrder;
            ViewBag.Category= Category;
            ViewBag.Brand= Brand;
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-22
    • 2023-04-06
    • 2011-05-03
    相关资源
    最近更新 更多