瑞雪年

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: :: 订阅 订阅 :: 管理 ::

Orchard 中的Pager是一个很方便的用来分页的Shape, 但默认情况下,它是使用当前Action的地址作为链接地址,如果分页的数据要是由别的Action提供时,这样的分页链接就不对了,其实它是支持自定义Action的,在Pager的源代码中

            var routeData = new RouteValueDictionary(Html.ViewContext.RouteData.Values);
            var queryString = _workContext.Value.HttpContext.Request.QueryString;
            if (queryString != null) {
                foreach (var key in from string key in queryString.Keys where key != null && !routeData.ContainsKey(key) let value = queryString[key] select key) {
                    routeData[key] = queryString[key];
                }
            }

            // specific cross-requests route data can be passed to the shape directly (e.g., Orchard.Users)
            var shapeRoute = (object)Shape.RouteData;

            if (shapeRoute != null) {
                var shapeRouteData = shapeRoute as RouteValueDictionary;
                if (shapeRouteData == null) {
                    var route = shapeRoute as RouteData;
                    if (route != null) {
                        shapeRouteData = (route).Values;    
                    }
                }

                if (shapeRouteData != null) {
                    foreach (var rd in shapeRouteData) {
                        routeData[rd.Key] = rd.Value;
                    }
                }
            }

可以看到,设置RouteData,可以改变默认的routeData,这样使用起来也很方便:

                Pager = Shape.Pager(pager)
                    .TotalItemCount(totalItemCount)
                    .RouteData(new RouteValueDictionary  
                        {
                            {"action", "Table"}
                        });

 

posted on 2013-12-15 19:45  瑞雪年  阅读(936)  评论(0编辑  收藏  举报