【问题标题】:PagedListPager pass additional model dataPagedListPager 传递额外的模型数据
【发布时间】:2012-12-30 15:19:43
【问题描述】:

我有以下型号:

  public class PagedClientViewModel
    {
        public int? Page { get; set; }
        public PagedList.PagedList<ClientViewModel> Clients { get; set; }               
        public bool ShowAllClients { get; set; }
    }

ShowAllClients 是一个复选框,我将使用它来进一步过滤从服务器返回的客户端列表。

 @Html.CheckBoxFor(model => model.ShowAllClients, new { id = "ShowAllClientsCheckbox" })

这是我的寻呼机:

@Html.PagedListPager(Model.Clients, page => Url.Action("Index", new { Page = page }), PagedListRenderOptions.DefaultPlusFirstAndLast)

寻呼机和复选框都在同一个表单上。

我遇到的问题是,当我在寻呼机控件上更改页面时,复选框始终设置为 false。发生这种情况是因为在 Index 操作中,ShowAllClients 设置为 false。

更改页面时如何保留复选框数据?

【问题讨论】:

    标签: c# asp.net-mvc pagedlist


    【解决方案1】:

    我让它与以下内容一起使用:

     @Html.PagedListPager(Model.Clients, page => Url.Action("Index", new PagedClientViewModel { Page = page, ShowAllClients = Model.ShowAllClients }))
    

    【讨论】:

      【解决方案2】:

      目前找到的最佳解决方案是:

      @Html.PagedListPager(Model.Clients, page => Url.Action("Index", new { Page = page, param1="",param2="" }), PagedListRenderOptions.DefaultPlusFirstAndLast)
      

      是的,它有效。

      【讨论】:

      • 感谢您提供快速简便的解决方案。
      【解决方案3】:

      在我的例子中,模型是 PagedList.IPagedList。除此之外,我使用了一个“SearchModel”,它存储在 ViewBag 中,因此可以轻松传递。我只需要更新页码。

      @Html.PagedListPager(Model, page =>
      {
          ViewBag.SearchModel.Page = page;
          return Url.Action("Index", "Search", ViewBag.SearchModel);
      })
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-11-03
        • 1970-01-01
        相关资源
        最近更新 更多