0

父视图:

var pagingModel = new Watchlist_Web.Models.ViewModel.PagingPartialViewModel();
                pagingModel.PagedList = Model;
                pagingModel.UrlAction = "AdminIndex";

                Dictionary<string, object> parameters = new Dictionary<string, object>();
                parameters.Add("query", Request.QueryString["query"]);
                parameters.Add("modelClass", Request.QueryString["nodeClassId"]);

                pagingModel.RouteValues = new RouteValueDictionary(parameters);

                pagingModel.ContainerDivClasses = "pagination-sm col-md-5";
@Html.Partial("_PagingPartial", pagingModel)

局部视图:

@using PagedList;
@using PagedList.Mvc;

@model Watchlist_Web.Models.ViewModel.PagingPartialViewModel
@Html.PagedListPager(Model.PagedList, page => Url.Action(Model.UrlAction,
        new RouteValueDictionary(new { page = page })),
        new PagedListRenderOptions()
                {
                    DisplayPageCountAndCurrentLocation = true,
                    DisplayLinkToFirstPage = PagedListDisplayMode.IfNeeded,
                    DisplayLinkToLastPage = PagedListDisplayMode.IfNeeded,
                    ContainerDivClasses = new[] { Model.ContainerDivClasses }
                })

我正在尝试将 Model.RouteValues 添加到 PagedListPager 的部分视图的 HTML 帮助程序中。URL.Action 的第二个参数是我需要指定路由值的地方,并且只有“页面”效果很好。但是,我正在尝试找到一种将 Model.RouteValues 的键/值对添加到此参数的方法。

4

1 回答 1

1

实现了将“页面”添加到新字典的实用程序类和方法。

实用方法:

public static RouteValueDictionary GetPagingRouteValDictionary(int page, RouteValueDictionary dict)
    {
        if (dict["page"] != null)
        {
            dict.Remove("page");
        }

        var newDict = new RouteValueDictionary(dict);
        newDict.Add("page", page);

        return newDict;
    }

局部视图:

@Html.PagedListPager(Model.PagedList, page => Url.Action(Model.UrlAction,
    Watchlist_Web.Utility.RouteValueDictUtil.GetPagingRouteValDictionary(page, Model.RouteValues)),

    new PagedListRenderOptions()
                {
                    DisplayPageCountAndCurrentLocation = true,
                    DisplayLinkToFirstPage = PagedListDisplayMode.IfNeeded,
                    DisplayLinkToLastPage = PagedListDisplayMode.IfNeeded,
                    ContainerDivClasses = new[] { Model.ContainerDivClasses }
                })
于 2015-04-30T14:14:32.423 回答