コード例 #1
0
 public static MvcHtmlString GrouponPager <T>(this HtmlHelper helper, IPagedList <T> pagedList, RouteValueDictionary routeValues)
 {
     if (pagedList == null)
     {
         return(helper.Pager(new PagerOptions(), null));
     }
     return(helper.Pager(pagedList.TotalCount, pagedList.PageSize, pagedList.PageIndex, null, null, new PagerOptions()
     {
         ShowPagingInfo = true, ShowPageSizeDropDownList = true
     }, null, routeValues, null));
 }
コード例 #2
0
 public static MvcHtmlString PagerLIst <T>(this HtmlHelper helper, IPagedList <T> pagedList, int?id)
 {
     if (pagedList == null)
     {
         return(helper.Pager(new PagerOptions(), null));
     }
     return(helper.Pager(pagedList.TotalCount, pagedList.PageSize, pagedList.PageIndex, null, null, new PagerOptions()
     {
         ShowPagingInfo = true, ShowPageSizeDropDownList = true, CurrentPagerItemWrapperFormatString = "<span class=\"currentPage\">{0}</span>"
     }, null, id, null));
 }
コード例 #3
0
        public static Pager Pager(this HtmlHelper htmlHelper, IPagingData pagingData)
        {
            var pager = htmlHelper.Pager(pagingData.ItemsBase.PageSize, pagingData.ItemsBase.PageNumber, pagingData.ItemsBase.TotalItemCount,
                                         new AjaxOptions {
                UpdateTargetId = pagingData.ContainerName
            });

            var routeValues = pagingData.RouteValues ?? new RouteValueDictionary();

            // Because of a bug in MVCPaging 2.0.1 the action parameter needs to be specified in routevalues as well
            if (!string.IsNullOrEmpty(pagingData.Action) && !routeValues.ContainsKey("action"))
            {
                routeValues.Add("action", pagingData.Action);
            }

            if (pagingData.Id != null && !routeValues.ContainsKey("id"))
            {
                routeValues.Add("id", pagingData.Id);
            }

            if (pagingData.AddTotalCount && !routeValues.ContainsKey("totalCount"))
            {
                routeValues.Add("totalCount", pagingData.ItemsBase.TotalItemCount);
            }

            pager = pager.Options(o => o.RouteValues(routeValues));

            return(pager);
        }
コード例 #4
0
 /// <summary>
 /// The pager.
 /// </summary>
 /// <param name="helper">
 /// The helper.
 /// </param>
 /// <param name="pagedList">
 /// The paged list.
 /// </param>
 /// <returns>
 /// The <see cref="MvcHtmlString"/>.
 /// </returns>
 public static MvcHtmlString Pager(this HtmlHelper helper, IPagedList pagedList)
 {
     if (pagedList == null)
     {
         return(PagerHelper.Pager(helper, null, new Dictionary <string, object>()));
     }
     return(helper.Pager(pagedList.TotalItemCount, pagedList.PageSize, pagedList.CurrentPageIndex, null, null, null, null, null, null));
 }
コード例 #5
0
 /// <summary>
 /// The pager.
 /// </summary>
 /// <param name="helper">
 /// The helper.
 /// </param>
 /// <param name="pagedList">
 /// The paged list.
 /// </param>
 /// <param name="pagerOptions">
 /// The pager options.
 /// </param>
 /// <returns>
 /// The <see cref="MvcHtmlString"/>.
 /// </returns>
 public static MvcHtmlString Pager(this HtmlHelper helper, IPagedList pagedList, PagerOptions pagerOptions)
 {
     if (pagedList == null)
     {
         return(PagerHelper.Pager(helper, pagerOptions, null));
     }
     return(helper.Pager(pagedList.TotalItemCount, pagedList.PageSize, pagedList.CurrentPageIndex, null, null, pagerOptions, null, null, null));
 }
コード例 #6
0
 /// <summary>
 /// The pager.
 /// </summary>
 /// <param name="helper">
 /// The helper.
 /// </param>
 /// <param name="pagedList">
 /// The paged list.
 /// </param>
 /// <param name="pagerOptions">
 /// The pager options.
 /// </param>
 /// <param name="routeName">
 /// The route name.
 /// </param>
 /// <param name="routeValues">
 /// The route values.
 /// </param>
 /// <param name="htmlAttributes">
 /// The html attributes.
 /// </param>
 /// <returns>
 /// The <see cref="MvcHtmlString"/>.
 /// </returns>
 public static MvcHtmlString Pager(this HtmlHelper helper, IPagedList pagedList, PagerOptions pagerOptions, string routeName, object routeValues, object htmlAttributes)
 {
     if (pagedList == null)
     {
         return(PagerHelper.Pager(helper, pagerOptions, new RouteValueDictionary(htmlAttributes)));
     }
     return(helper.Pager(pagedList.TotalItemCount, pagedList.PageSize, pagedList.CurrentPageIndex, null, null, pagerOptions, routeName, routeValues, htmlAttributes));
 }
コード例 #7
0
 /// <summary>
 /// The pager.
 /// </summary>
 /// <param name="helper">
 /// The helper.
 /// </param>
 /// <param name="pagedList">
 /// The paged list.
 /// </param>
 /// <param name="routeName">
 /// The route name.
 /// </param>
 /// <param name="routeValues">
 /// The route values.
 /// </param>
 /// <param name="htmlAttributes">
 /// The html attributes.
 /// </param>
 /// <returns>
 /// The <see cref="MvcHtmlString"/>.
 /// </returns>
 public static MvcHtmlString Pager(this HtmlHelper helper, IPagedList pagedList, string routeName, RouteValueDictionary routeValues, IDictionary <string, object> htmlAttributes)
 {
     if (pagedList == null)
     {
         return(PagerHelper.Pager(helper, null, htmlAttributes));
     }
     return(helper.Pager(pagedList.TotalItemCount, pagedList.PageSize, pagedList.CurrentPageIndex, null, null, null, routeName, routeValues, htmlAttributes));
 }
コード例 #8
0
 public static MvcHtmlString Pager <T>(this HtmlHelper helper, IPagedList <T> pagedList)
 {
     if (pagedList == null)
     {
         return(Pager(helper, (PagerOptions)null, null));
     }
     return(helper.Pager(pagedList, new RouteValueDictionary()));
 }
コード例 #9
0
 public static string Pager(this HtmlHelper helper, string actionName, string controller,
                            int pageIndex, int maximumRows, int totalRowCount, int buttonCount, object routeValues,
                            object pageHtmAttributes, object buttonsHtmlAttributes)
 {
     return(helper.Pager(actionName, controller, pageIndex, maximumRows, totalRowCount, buttonCount,
                         (RouteValueDictionary)routeValues, new RouteValueDictionary(pageHtmAttributes),
                         new RouteValueDictionary(buttonsHtmlAttributes)));
 }
コード例 #10
0
 public static MvcHtmlString Pager(this HtmlHelper helper, IPagedList pagedList, PagerOptions pagerOptions, IDictionary <string, object> htmlAttributes)
 {
     if (pagedList == null)
     {
         return(Pager(helper, pagerOptions, htmlAttributes));
     }
     return(helper.Pager(pagedList.TotalItemCount, pagedList.PageSize, pagedList.CurrentPageIndex, null, null, pagerOptions, null, null, htmlAttributes));
 }
コード例 #11
0
 public static MvcHtmlString LMSPager <T>(this HtmlHelper helper, IPagedList <T> pagedList, RouteValueDictionary routeValues)
 {
     if (pagedList == null)
     {
         return(helper.Pager(new PagerOptions(), null));
     }
     return(helper.Pager(pagedList.TotalCount, pagedList.PageSize, pagedList.PageIndex, null, null,
                         new PagerOptions()
     {
         AutoHide = false, ShowFirstLast = false, ShowPagingInfo = false,
         ShowPageSizeDropDownList = false,
         CurrentPagerItemWrapperFormatString = "<li class=\"page_itembox current\"><a href=\"\">{0}</a></li>",
         ContainerTagName = "ul", CssClass = "l pl2",
         PagerItemWrapperFormatString = "<li class=\"page_itembox\">{0}</li>",
         NavigationPagerItemWrapperFormatString = "<li class=\"page_itembox\">{0}</li>"
     }, null, routeValues, null));
 }
コード例 #12
0
ファイル: PagerTests.cs プロジェクト: atomicobject/mvccontrib
 public void Should_create_pager_from_datasource()
 {
     var helper = new HtmlHelper(new ViewContext() { HttpContext = _context }, MockRepository.GenerateStub<IViewDataContainer>());
     helper
         .Pager(_datasource.AsPagination(1, 2))
         .ToString()
         .Contains("Showing 1 - 2 of 3").ShouldBeTrue();
 }
コード例 #13
0
        public static MvcHtmlString MvcPager <T>(this HtmlHelper helper, IEnumerable <T> list)
        {
            var pagelist = list as IPagedList;

            return(helper.Pager(pagelist, new PagerOptions()
            {
                AutoHide = false, NumericPagerItemCount = 5
            }));
        }
コード例 #14
0
        public static string Pager(
            this HtmlHelper htmlHelper,
            IPagedList pagedList)
        {
            string controller = htmlHelper.ViewContext.RouteData.Values["controller"].ToString();
            string action     = htmlHelper.ViewContext.RouteData.Values["action"].ToString();

            return(htmlHelper.Pager(controller, action, pagedList));
        }
コード例 #15
0
        /// <summary>
        /// 分页方法
        /// </summary>
        /// <param name="html"></param>
        /// <param name="routeName">使用的路由名称</param>
        /// <param name="routeValues">使用的路由的值</param>
        /// <param name="option">分页选项</param>
        /// <returns></returns>
        public static MvcHtmlString Pager(this HtmlHelper html, string routeName, object routeValues, PagerOption option)
        {
            var routeValue = new RouteValueDictionary();

            if (routeValues != null)
            {
                routeValue = GetDictionary <RouteValueDictionary>(routeValues, option);
            }
            return(html.Pager(routeName, routeValue, option));
        }
コード例 #16
0
ファイル: PagerTests.cs プロジェクト: zfq308/AspNet.Mvc.Grid
        public void Should_create_pager_from_datasource()
        {
            var helper = new HtmlHelper(new ViewContext()
            {
                HttpContext = _context
            }, MockRepository.GenerateStub <IViewDataContainer>());

            helper
            .Pager(_datasource.AsPagination(1, 2))
            .ToString()
            .Contains("Showing 1 - 2 of 3").ShouldBeTrue();
        }
コード例 #17
0
        public static Pager Pager(this HtmlHelper helper, string viewDataKey)
        {
            var dataSource = helper.ViewContext.ViewData.Eval(viewDataKey) as IPageableModel;

            if (dataSource == null)
            {
                throw new InvalidOperationException(string.Format("Item in ViewData with key '{0}' is not an IPagination.",
                                                                  viewDataKey));
            }

            return(helper.Pager(dataSource));
        }
コード例 #18
0
        public static MvcHtmlString Pager <T>(this HtmlHelper helper, PageList <T> pageList, string actionName, string controllerName, string routeName, int numericPagerItemCount, bool autoHide, object routeValues, object htmlAttributes)
        {
            if (pageList == null)
            {
                pageList = new PageList <T>(20);
            }
            var mvcHtml = helper.Pager(pageList.ItemCount, pageList.PageSize, pageList.PageIndex, new PagerOptions()
            {
                Id                              = "mvcPager",
                ActionName                      = actionName,
                ControllerName                  = controllerName,
                RouteName                       = routeName,
                RouteValues                     = new System.Web.Routing.RouteValueDictionary(routeValues),
                HtmlAttributes                  = htmlAttributes as System.Collections.Generic.Dictionary <string, object>,
                GoToButtonId                    = "mvcGoToButtonId",
                PageIndexBoxId                  = "mvcPageIndexBoxId",
                PageIndexParameterName          = "pageIndex",
                InvalidPageIndexErrorMessage    = "索引值不是有效的数值类型!",
                PageIndexOutOfRangeErrorMessage = "页索引超出范围!",
                OnPageIndexError                = @"cy.message([errMsg], { level: 4 });",
                ContainerTagName                = "ul",
                PrevPageText                    = "上页",
                NextPageText                    = "下页",
                FirstPageText                   = "首页",
                LastPageText                    = "尾页",
                CssClass                        = "pager",
                CurrentPagerItemTemplate        = "<li class=\"active\"><a href=\"javascript:;\">{0}</a></li>",
                PagerItemTemplate               = "<li>{0}</li>",
                DisabledPagerItemTemplate       = "<li><a disabled=\"disabled\" href=\"javascript:;\">{0}</a></li>",
                AutoHide                        = autoHide,
                NumericPagerItemCount           = numericPagerItemCount,
            });

            helper.RegisterMvcPagerScriptResource();

            return(new MvcHtmlString(
                       "<div class=\"pagerbar\"><span class=\"pagerinfo\">总计"
                       + pageList.PageCount + "页/"
                       + pageList.ItemCount + "条记录</span>"
                       + mvcHtml.ToHtmlString().Replace("<!--MvcPager v2.0 for ASP.NET MVC 4.0+ © 2009-2013 Webdiyer (http://www.webdiyer.com)-->", "").Replace("\r\n", "")
                       + "<span class=\"pagergoto\">跳转到第<input id=\"mvcPageIndexBoxId\" value=\"" + pageList.PageIndex + "\"></input>页<button id=\"mvcGoToButtonId\">跳转</button></span>"
                       + "</div>"
                       + @"<script type='text/javascript'>
                    $(function () {
                        $('#mvcPageIndexBoxId').keydown(function(e){
                            if(e.keyCode==13){
                                $('#mvcGoToButtonId').click();
                            }
                        });
                    });
                    </script>"));
        }
コード例 #19
0
        /// <summary>
        /// Generates a pager from a paged result set.
        /// </summary>
        public static IHtmlString PagerFor <TModel, TProperty>(this HtmlHelper <TModel> htmlHelper, Expression <Func <TModel, TProperty> > expression,
                                                               Func <int, string> pageUrlGenerator, object htmlAttributes = null)
            where TProperty : IPagedList
        {
            var stats = ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData).Model as IPagedList;

            if (stats == null || !stats.HasResults || stats.TotalPages <= 1)
            {
                return(MvcHtmlString.Empty);
            }

            return(htmlHelper.Pager(stats.Page, stats.TotalPages, pageUrlGenerator, htmlAttributes));
        }
コード例 #20
0
ファイル: PagerTests.cs プロジェクト: zfq308/AspNet.Mvc.Grid
        public void Should_throw_when_item_in_viewdata_is_not_ipagination()
        {
            var helper = new HtmlHelper(
                new ViewContext
            {
                ViewData = new ViewDataDictionary {
                    { "data", new object() }
                }
            },
                MockRepository.GenerateStub <IViewDataContainer>()
                );

            helper.Pager("data");
        }
コード例 #21
0
        public static MvcHtmlString Paginaton(this HtmlHelper helper, IPagedList pagedList)
        {
            var pagerOptions = new PagerOptions
            {
                PageIndexParameterName = "page",
                CssClass      = "pagination",
                ShowFirstLast = false,
                AlwaysShowFirstLastPageNumber = true,
                ShowMorePagerItems            = true,
                NumericPagerItemCount         = 5,
                PagerItemsSeperator           = string.Empty,
            };

            return(helper.Pager(pagedList, pagerOptions));
        }
コード例 #22
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void PagerOptions_AlwaysShowFirstLastPageNumberWithCurrentPageIndexIs12_ShouldGenerateCorrectHtml()
 {
     _testList.PageSize = 2;
     _testList.CurrentPageIndex = 12;
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id", AlwaysShowFirstLastPageNumber = true});
     string htmlStr = html.ToHtmlString();
     const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-currentpage=\"12\"", "data-firstpage=\"" + BaseLink + "\"",
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"44\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("<a href=\"").Append(BaseLink).Append("\">First</a>");
     sb.AppendFormat(linkFormat, 11, "Prev");
     sb.Append("<a href=\"").Append(BaseLink).Append("\">1</a>");
     sb.AppendFormat(linkFormat, 6, "...");
     for (int i = 7; i <= 16; i++)
     {
         if (i == 12)
             sb.Append(i);
         else
         {
             sb.AppendFormat(linkFormat, i, i);
         }
     }
     sb.AppendFormat(linkFormat, 17, "...");
     sb.AppendFormat(linkFormat, 44, "44");
     sb.AppendFormat(linkFormat, 13, "Next");
     sb.AppendFormat(linkFormat, 44, "Last");
     sb.Append("</div>");
     sb.Append(TestHelper.CopyrightText);
     Assert.AreEqual(htmlStr, sb.ToString());
 }
コード例 #23
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void PagerOptions_MaximumPageNumberIs8_ShouldGenerateCorrectHtml()
 {
     _testList.PageSize = 5;
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList,
                                            new PagerOptions
                                            {
                                                PageIndexParameterName = "id",
                                                MaximumPageNumber = 8,RouteName = "Default"
                                            });
     string htmlStr = html.ToHtmlString();
     const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"8\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("FirstPrev1");
     for (int i = 2; i <= 8; i++)
     {
             sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 2, "Next");
     sb.AppendFormat(linkFormat, 8, "Last");
     sb.Append("</div>");
     sb.Append(TestHelper.CopyrightText);
     Assert.AreEqual(htmlStr,sb.ToString());
 }
コード例 #24
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void SetAllParameters_ShouldGenerateCorrectHtml()
 {
     const string rootLink = AppPathModifier + "/MyController/MyAction";
     const string linkFormat = "<a href=\"" + rootLink + "/{0}?city=Wuqi&nick=Webdiyer\">{1}</a>";
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(88, 10, 1).Options(o=>o.SetActionName("MyAction").SetControllerName("MyController").
                                                SetPageIndexParameterName("id").
                                                SetFirstPageText("First Page").SetPrevPageText("Prev Page").
                                                SetNextPageText("Next Page").SetLastPageText("Last Page").
                                                SetRouteValues(new RouteValueDictionary { { "Controller", "MyController" }, { "Action", "MyAction" }, { "city", "Wuqi" }, { "nick", "Webdiyer" } }).
                                                SetHtmlAttributes(new Dictionary<string, object> { { "id", "mypager" } }));
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"9\"",
         "data-urlformat=\""+rootLink+"/__id__?city=Wuqi&amp;nick=Webdiyer\"","id=\"mypager\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("First PagePrev Page1");
     for (int i = 2; i <= 9; i++)
     {
         sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, "2", "Next Page");
     sb.AppendFormat(linkFormat, "9", "Last Page");
     sb.Append("</div>").Append(TestHelper.CopyrightText);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #25
0
        /// <summary>
        /// Returns a Pager object.
        /// </summary>
        /// <param name="htmlHelper"></param>
        /// <param name="pageSize">Sets the size of a page.</param>
        /// <param name="currentPage">Sets the current page.</param>
        /// <param name="totalItemCount">Sets the number of items.</param>
        /// <param name="action">Sets an alternative action for the pager that is different from the current action.</param>
        /// <param name="alwaysAddFirstPageNumber">If true it will add the page number for page 1 too.</param>
        /// <param name="displayFirstAndLastPage">If true displays first and last navigation pages.</param>
        /// <param name="displayTemplate">When set, the internal HTML rendering is bypassed and a DisplayTemplate view with the given name is rendered instead. Note that the DisplayTemplate must have a model of type PaginationModel.</param>
        /// <param name="maxNrOfPages">Sets the maximum number of pages to show.</param>
        /// <param name="pageRouteValueKey">Sets the page routeValue key for pagination links.</param>
        /// <param name="routeValues">Adds route value parameters that are added to the page url's.</param>
        /// <param name="setFirstPageText">Sets a custom text for the first page.</param>
        /// <param name="setFirstPageTitle">Sets a custom text for title attribute of the first page link.</param>
        /// <param name="setLastPageText">Sets a custom text for the last page.</param>
        /// <param name="setLastPageTitle">Sets a custom text for title attribute of the last page link.</param>
        /// <param name="setNextPageText">Sets a custom text for the next page.</param>
        /// <param name="setNextPageTitle">Sets a custom text for title attribute of the next page link.</param>
        /// <param name="setPreviousPageText">Sets a custom text for the previous page.</param>
        /// <param name="setPreviousPageTitle">Sets a custom text for title attribute of the previous page link.</param>
        /// <param name="useItemCountAsPageCount">The totalItemCount parameter is (ab)used for the total number of pages instead of the total number of items to facilitate backends that return the total number of pages instead of the total number of items.</param>
        /// <returns></returns>
        public static Pager BootstrapPager(this HtmlHelper htmlHelper,
                                           int pageSize,
                                           int currentPage,
                                           int totalItemCount,
                                           string action = null,
                                           bool alwaysAddFirstPageNumber = true,
                                           bool displayFirstAndLastPage  = false,
                                           string displayTemplate        = "MvcPagingBootstrap3",
                                           int?maxNrOfPages                 = 3,
                                           string pageRouteValueKey         = "p",
                                           RouteValueDictionary routeValues = null,
                                           string setFirstPageText          = "«",
                                           string setFirstPageTitle         = null,
                                           string setLastPageText           = "»",
                                           string setLastPageTitle          = null,
                                           string setNextPageText           = "›",
                                           string setNextPageTitle          = null,
                                           string setPreviousPageText       = "‹",
                                           string setPreviousPageTitle      = null,
                                           bool useItemCountAsPageCount     = false)
        {
            Pager result = htmlHelper.Pager(pageSize, currentPage, totalItemCount);

            if (alwaysAddFirstPageNumber)
            {
                result.Options(o => o.AlwaysAddFirstPageNumber());
            }

            if (displayFirstAndLastPage)
            {
                result.Options(o => o.DisplayFirstAndLastPage());
            }

            if (displayTemplate.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.DisplayTemplate(displayTemplate));
            }

            if (maxNrOfPages.IsNotNull())
            {
                result.Options(o => o.MaxNrOfPages((int)maxNrOfPages));
            }

            if (pageRouteValueKey.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.PageRouteValueKey(pageRouteValueKey));
            }

            if (routeValues.IsNotNull())
            {
                result.Options(o => o.RouteValues(routeValues));
            }

            if (setFirstPageText.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetFirstPageText(setFirstPageText));
            }

            if (setFirstPageTitle.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetFirstPageTitle(setFirstPageTitle));
            }

            if (setLastPageText.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetLastPageText(setLastPageText));
            }

            if (setLastPageTitle.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetLastPageTitle(setLastPageTitle));
            }

            if (setNextPageText.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetNextPageText(setNextPageText));
            }

            if (setNextPageTitle.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetNextPageTitle(setNextPageTitle));
            }

            if (setPreviousPageText.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetPreviousPageText(setPreviousPageText));
            }

            if (setPreviousPageTitle.IsNotEmptyOrWhiteSpace())
            {
                result.Options(o => o.SetPreviousPageTitle(setPreviousPageTitle));
            }

            return(result);
        }
コード例 #26
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void DefaultRoute_NullPagerOptions_ShouldGenerateCorrectHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 1;
     const string linkFormat = "<a href=\"" + BaseLink + "/2?pageindex={0}\">{1}</a>";
     IHtmlString html = _htmlHelper.Pager(_testList,null);
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"pageindex\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\""+BaseLink+"/2?pageindex=__pageindex__\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("First").Append("Prev").Append("1");
     for (int i = 2; i <= 10; i++)
     {
         sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 11, "...");
     sb.AppendFormat(linkFormat, 2, "Next");
     sb.AppendFormat(linkFormat, 11, "Last");
     sb.Append("</div>").Append(TestHelper.CopyrightText);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #27
0
 public static MvcHtmlString Pager <T>(this HtmlHelper helper, IPagedList <T> pagedList, object routeValues)
 {
     return(helper.Pager(pagedList, new RouteValueDictionary(routeValues)));
 }
コード例 #28
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void PagerOptions_PageIndexErrorMessage_ShouldReturnCorrectString()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").SetPageIndexOutOfRangeErrorMessage("Out of range").SetInvalidPageIndexErrorMessage("Invalid page index"));
     string htmlStr = html.ToHtmlString();
     StringAssert.Contains(htmlStr, " data-outrangeerrmsg=\"Out of range\" ");
     StringAssert.Contains(htmlStr, " data-invalidpageerrmsg=\"Invalid page index\"");
 }
コード例 #29
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void PagerOptions_MaximumPageIndexItemsIs6_ShouldGenerateCorrectHtml()
 {
     _testList.PageSize = 5;
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").SetPageIndexBoxId("pib").SetMaximumPageIndexItems(6));
     string htmlStr = html.ToHtmlString();
     var attrs = new[]
     {
         "data-maxitems=\"6\"","data-pageindexbox=\"#pib\"",
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"18\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     var sb = new StringBuilder("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     StringAssert.Contains(htmlStr,sb.ToString());
 }
コード例 #30
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
        public void AlwaysShowFirstLastPageNumberWithPageIndexIs7_ShouldGenerateCorrectHtml()
        {
            _htmlHelper = TestHelper.GetHtmlHelper();
            _testList.PageSize = 5;
            _testList.CurrentPageIndex = 7;
            var po = new PagerOptions
            {
                PageIndexParameterName = "id",
                AlwaysShowFirstLastPageNumber = true,
                ShowFirstLast = false,
                ShowPrevNext = false
            };


            IHtmlString html = _htmlHelper.Pager(_testList, po);
            const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
            var sb = new StringBuilder(TestHelper.CopyrightText);
            var attrs = new[]
            {
                "data-currentpage=\"7\"", "data-firstpage=\"" + BaseLink + "\"",
                "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
                "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
                "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"18\"",
                "data-urlformat=\"" + BaseLink + "/__id__\""
            };
            sb.Append("<div");
            foreach (var att in attrs.OrderBy(a => a))
            {
                sb.Append(" ").Append(att);
            }
            sb.Append(">");
            sb.Append("<a href=\"" + BaseLink + "\">1</a>");
            for (int i = 2; i <= 11; i++)
            {
                if (i == 7)
                    sb.Append(i);
                else
                    sb.AppendFormat(linkFormat, i, i);
            }
            sb.AppendFormat(linkFormat, 12, "...");
            sb.AppendFormat(linkFormat, 18, 18);
            sb.Append("</div>").Append(TestHelper.CopyrightText);
            Assert.AreEqual(html.ToHtmlString(), sb.ToString());
        }
コード例 #31
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void CustomRoute_CurrentPageIndexIs1_ShouldGenerateCorrectFirstPageUrlAndUrlFormatAttributes()
 {
     _htmlHelper = TestHelper.GetHtmlHelper(
                                           new RouteValueDictionary
                                               {
                                                   {"controller", "Controls"},
                                                   {"action", "MvcPager"}
                                               });
     var pagingRoute = _htmlHelper.RouteCollection.MapRoute("Paging", "{controller}/{action}/page_{id}",
                                                            new {controller = "Home", action = "Index", id = 1});
     _htmlHelper.ViewContext.RouteData.Route = pagingRoute;
     _testList.CurrentPageIndex = 8;
     IHtmlString html =
         _htmlHelper.Pager(_testList).Options(o => o.SetPageIndexParameterName("id").SetRouteName("Paging"));
     string htmlStr = html.ToHtmlString();
     StringAssert.Contains(htmlStr," data-firstpage=\"" + AppPathModifier + "/Controls/MvcPager/page_1\"",
                   "Url of the first page is incorrect");
     StringAssert.Contains(htmlStr," data-urlformat=\"" + AppPathModifier + "/Controls/MvcPager/page___id__\"",
         "Paging url format is incorrect");
 }
コード例 #32
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void MultipleMvcPagersWithExtraRouteValues_ShouldGenerateCorrectUrlWithParameters()
 {
     _htmlHelper =
         TestHelper.GetHtmlHelper(new RouteValueDictionary { { "author", "Webdiyer" }, { "city", "Wuqi" }, { "id", 6 } });
     _htmlHelper.Pager(_testList, new PagerOptions
     {
         PageIndexParameterName = "id"
     });
     _testList.CurrentPageIndex = 5;
     IHtmlString html = _htmlHelper.Pager(_testList);
     var htmlStr = html.ToHtmlString();
     StringAssert.Contains(htmlStr, " data-firstpage=\"" + BaseLink + "/6?author=Webdiyer&amp;city=Wuqi\"",
         "Value of firstpage data attribute of the second MvcPager is incorrent");
     StringAssert.Contains(htmlStr, " data-urlformat=\"" + BaseLink + "/6?author=Webdiyer&amp;city=Wuqi&amp;pageindex=__pageindex__",
         "Value of urlformat data attribute of the second MvcPager is incorrect");
 }
コード例 #33
0
 public static MvcHtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, string actionName, string labelPrevious, string labelNext)
 {
     return(htmlHelper.Pager(pageSize, currentPage, totalItemCount, actionName, null, labelPrevious, labelNext));
 }
コード例 #34
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void SetHtmlAttributesWithStyleValue_ShouldGenerateCorrectStyleAttribute()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").SetHorizontalAlign("right").HidePagerItems().SetHtmlAttributes(new Dictionary<string, object> { { "style", "width:95%;height:28px" } } ));
     StringAssert.Contains(html.ToHtmlString(), " style=\"width:95%;height:28px;text-align:right;display:none\"");
 }
コード例 #35
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void HtmlAttributesWithStyleValue_ShouldGenerateCorrectStyleAttribute()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id",HorizontalAlign = "right",HidePagerItems = true,  HtmlAttributes = new Dictionary<string, object> { { "style", "width:95%;height:28px" }}});
     StringAssert.Contains(html.ToHtmlString(), " style=\"width:95%;height:28px;text-align:right;display:none\"");
 }
コード例 #36
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void CustomHtmlAttributesValue_ShouldGenerateCorrectHtmlAttributes()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id", HtmlAttributes = new Dictionary<string, object> { { "aaa", "98%" }, { "bbb", "26px" }, { "ccc", "both" } } });
     var attrs = new[]
     {
         "aaa=\"98%\"", "bbb=\"26px\"","ccc=\"both\"",
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     var sb=new StringBuilder("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     StringAssert.Contains(html.ToHtmlString(), sb.ToString());
 }
コード例 #37
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void CurrentUICultureIsZhCN_ShouldGetCorrectPropertyValuesFromResourceFile()
 {
     Thread.CurrentThread.CurrentUICulture = CultureInfo.CreateSpecificCulture("zh-CN");
     _testList.PageSize = 5;
     _testList.CurrentPageIndex = 13;
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList,
                                            new PagerOptions
                                            {
                                                PageIndexParameterName = "id"
                                            });
     const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
     var sb = new StringBuilder(TestHelper.CopyrightTextCn);
     var attrs = new[]
     {
         "data-currentpage=\"13\"", "data-firstpage=\"" + BaseLink + "\"",
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessageCn + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessageCn + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"18\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("<a href=\"").Append(BaseLink).Append("\">首页</a>");
     sb.AppendFormat(linkFormat, 12, "上页");
     sb.AppendFormat(linkFormat, 7, "...");
     for (int i = 8; i < 18; i++)
     {
         if (i == 13)
             sb.Append(i);
         else
             sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 18, "..."); 
     sb.AppendFormat(linkFormat, 14, "下页");
     sb.AppendFormat(linkFormat, 18, "尾页");
     sb.Append("</div>").Append(TestHelper.CopyrightTextCn);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #38
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void SetCurrentPageNumberFormatStringAndPagerItemTemplate_ShouldGenerateCorrectHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
     _testList.CurrentPageIndex = 6;
     IHtmlString html = _htmlHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").SetCurrentPagerItemTemplate("<span class=\"current\">{0}</span>").SetCurrentPageNumberFormatString("-{0}-"));
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-currentpage=\"6\"","data-firstpage=\"" + BaseLink + "\"",
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.AppendFormat("<a href=\"{0}\">First</a>", BaseLink);
     sb.AppendFormat(linkFormat, 5, "Prev");
     sb.AppendFormat("<a href=\"{0}\">1</a>", BaseLink);
     for (int i = 2; i <= 10; i++)
     {
         if (i == 6)
             sb.Append("<span class=\"current\">-6-</span>");
         else
             sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 11, "...");
     sb.AppendFormat(linkFormat, 7, "Next");
     sb.AppendFormat(linkFormat, 11, "Last");
     sb.Append("</div>").Append(TestHelper.CopyrightText);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #39
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void DefaultRoute_DefaultPageIndexParameterNameWithExtrIdRouteData_ShouldGenerateCorrectLinks()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 4;
     IHtmlString html = _htmlHelper.Pager(_testList);
     string htmlStr = html.ToHtmlString();
     StringAssert.Contains(htmlStr, " data-firstpage=\"" + BaseLink + "/2\"",
                   "first page url is incorrect");
     StringAssert.Contains(htmlStr, "<a href=\"" + BaseLink + "/2?pageindex=3\">3</a>",
                   "paging link is incorrect");
     StringAssert.Contains(htmlStr, " data-urlformat=\"" + BaseLink + "/2?pageindex=__pageindex__\"",
         "url format is incorrect");
 }
コード例 #40
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void DisabledPagerItemTemplate_ShouldGenerateCorrectHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
     IHtmlString html = _htmlHelper.Pager(_testList,
                                            new PagerOptions
                                            {
                                                PageIndexParameterName = "id",
                                                DisabledPagerItemTemplate = "<span class=\"disabled\">{0}</span>"
                                            });
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("<span class=\"disabled\">First</span>")
         .Append("<span class=\"disabled\">Prev</span>")
         .Append("1");
     for (int i = 2; i <= 10; i++)
     {
         sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 11, "...");
     sb.AppendFormat(linkFormat, 2, "Next");
     sb.AppendFormat(linkFormat, 11, "Last");
     sb.Append("</div>").Append(TestHelper.CopyrightText);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #41
0
        public static MvcHtmlString Pager(this HtmlHelper helper)
        {
            var model = (ViewModelListBase)helper.ViewData.Model;

            return(helper.Pager(model.List, model.PagerOptions));
        }
コード例 #42
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void SetDisabledPagerItemTemplate_ShouldOverridePagerItemTemplate()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     const string linkFormat = "<li><a href=\"" + BaseLink + "/{0}\">{1}</a></li>";
     IHtmlString html = _htmlHelper.Pager(_testList).Options(o=>o.SetContainerTagName("ul").SetPageIndexParameterName("id").
                                                SetDisabledPagerItemTemplate("<li class=\"disabled\">{0}</li>").
                                                SetCurrentPagerItemTemplate("<li class=\"current\">{0}</li>").
                                                SetPagerItemTemplate("<li>{0}</li>"));
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\"" + BaseLink + "/__id__\""
     };
     sb.Append("<ul");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("<li class=\"disabled\">First</li>")
         .Append("<li class=\"disabled\">Prev</li>")
         .Append("<li class=\"current\">1</li>");
     for (int i = 2; i <= 10; i++)
     {
         sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 11, "...");
     sb.AppendFormat(linkFormat, 2, "Next");
     sb.AppendFormat(linkFormat, 11, "Last");
     sb.Append("</ul>").Append(TestHelper.CopyrightText);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #43
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void SetOnPageIndexError_ShouldGenerateCorrectHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 1;
     const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
     IHtmlString html = _htmlHelper.Pager(_testList).Options(o=>o.SetPageIndexParameterName("id").SetOnPageIndexError("alert('page index error:'+err)"));
     var sb = new StringBuilder(TestHelper.CopyrightText);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\"" + BaseLink + "/__id__\"","data-onerror=\"" + HttpUtility.HtmlEncode("alert('page index error:'+err)") + "\""
     };
     sb.Append("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">");
     sb.Append("First").Append("Prev").Append("1");
     for (int i = 2; i <= 10; i++)
     {
         sb.AppendFormat(linkFormat, i, i);
     }
     sb.AppendFormat(linkFormat, 11, "...").AppendFormat(linkFormat, 2, "Next");
     sb.AppendFormat(linkFormat, 11, "Last");
     sb.Append("</div>").Append(TestHelper.CopyrightText);
     Assert.AreEqual(html.ToHtmlString(), sb.ToString());
 }
コード例 #44
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void CurrentPagerItemTemplate_ShouldInheritFromNumericPagerItemTemplate()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 2;
     IHtmlString html = _htmlHelper.Pager(_testList,
                                            new PagerOptions
                                            {
                                                PageIndexParameterName = "id",
                                                NumericPagerItemTemplate ="<span class=\"number\">{0}</span>"
                                            });
     StringAssert.Contains(html.ToHtmlString(), "<span class=\"number\">2</span>");
 }
コード例 #45
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void CurrentPageIndexIsLargerThanTotalPageCount_ShouldGenerateCorrectHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 88;
     IHtmlString html = _htmlHelper.Pager(_testList, null);
     var attrs = new[]
     {
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"", "data-pagerid=\"Webdiyer.MvcPager\"",
         "style=\"color:red;font-weight:bold\""
     };
     var sb=new StringBuilder("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append(">").Append(TestHelper.PageIndexOutOfRangeErrorMessage).Append("</div>");
     Assert.AreEqual(html.ToHtmlString(), TestHelper.CopyrightText + sb + TestHelper.CopyrightText);
 }
コード例 #46
0
 public static MvcHtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, object values, string labelPrevious, string labelNext, string labelFirst, string labelLast)
 {
     return(htmlHelper.Pager(pageSize, currentPage, totalItemCount, null, new RouteValueDictionary(values), labelPrevious, labelNext, labelFirst, labelLast));
 }
コード例 #47
0
 // TODO: Add routeValues
 public static string Pager(this HtmlHelper helper, string actionName, string controller,
                            int pageIndex, int maximumRows, int totalRowCount, int buttonCount)
 {
     return(helper.Pager(actionName, controller, pageIndex, maximumRows, totalRowCount, buttonCount,
                         new RouteValueDictionary(), new RouteValueDictionary(), new RouteValueDictionary()));
 }
コード例 #48
0
		public void Should_throw_when_item_in_viewdata_is_not_ipagination()
		{
			var helper = new HtmlHelper(
				new ViewContext
				{
					ViewData = new ViewDataDictionary {{"data", new object()}}
				},
				MockRepository.GenerateStub<IViewDataContainer>()
				);

			helper.Pager("data");
		}
コード例 #49
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void DisabledPagerItemTemplate_ShouldInheritFromNavigationPagerItemTemplate()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     IHtmlString html = _htmlHelper.Pager(_testList,
                                            new PagerOptions
                                            {
                                                PageIndexParameterName = "id",
                                                NavigationPagerItemTemplate = "<span class=\"navbtn\">{0}</span>"
                                            });
     StringAssert.Contains(html.ToHtmlString(), "<span class=\"navbtn\">First</span>");
 }
コード例 #50
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
        public void SetAlwaysShowFirstLastPageNumber_PageIndexIs13AndPageSizeIs5_ShouldGenerateCorrectHtml()
        {
            _testList.PageSize = 5;
            _testList.CurrentPageIndex = 13;

            _htmlHelper = TestHelper.GetHtmlHelper();

            IHtmlString html = _htmlHelper.Pager(_testList).Options(o => o.SetPageIndexParameterName("id").AlwaysShowFirstLastPageNumber().HideFirstLast().HidePrevNext());
            const string linkFormat = "<a href=\"" + BaseLink + "/{0}\">{1}</a>";
            var sb = new StringBuilder(TestHelper.CopyrightText);
            var attrs = new[]
            {
                "data-currentpage=\"13\"","data-firstpage=\"" + BaseLink + "\"",
                "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
                "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
                "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"18\"",
                "data-urlformat=\""+BaseLink+"/__id__\""
            };
            sb.Append("<div");
            foreach (var att in attrs.OrderBy(a => a))
            {
                sb.Append(" ").Append(att);
            }
            sb.Append(">");
            sb.Append("<a href=\"" + BaseLink + "\">1</a>");
            sb.Append("<a href=\"" + BaseLink + "/7\">...</a>");
            for (int i = 8; i <= 18; i++)
            {
                if (i == 13)
                    sb.Append(i);
                else
                    sb.AppendFormat(linkFormat, i, i);
            }
            sb.Append("</div>").Append(TestHelper.CopyrightText);
            Assert.AreEqual(html.ToHtmlString(), sb.ToString());
        }
コード例 #51
0
 public static IHtmlString Pager(this HtmlHelper htmlHelper, int pageIndex, int pageSize)
 {
     return(htmlHelper.Pager(new Pager(pageIndex, pageSize)));
 }
コード例 #52
0
        /// <summary>
        /// 分页方法
        /// </summary>
        /// <param name="html"></param>
        /// <param name="routeName">使用的路由名称</param>
        /// /// <param name="option">分页选项</param>
        /// <returns></returns>
        public static MvcHtmlString Pager(this HtmlHelper html, string routeName, PagerOption option)
        {
            var routeValue = new RouteValueDictionary();

            return(html.Pager(routeName, routeValue, option));
        }
コード例 #53
0
 public static MvcHtmlString Pager(this HtmlHelper htmlHelper, int pageSize, int currentPage, int totalItemCount, RouteValueDictionary valuesDictionary, string labelPrevious, string labelNext)
 {
     return(htmlHelper.Pager(pageSize, currentPage, totalItemCount, null, valuesDictionary, labelPrevious, labelNext));
 }
コード例 #54
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void RouteWithConstraintOnPageIndexParameter_ShouldGenerateCorrectUrlFormat()
 {
     _htmlHelper = TestHelper.GetHtmlHelper(new RouteValueDictionary(new{controller="articles",action="list"}));
     _testList.CurrentPageIndex = 6;
     IHtmlString html = _htmlHelper.Pager(_testList,
         new PagerOptions
         {
             PageIndexParameterName = "id",
             RouteName = "constraintroute"
         });
     var htmlStr = html.ToHtmlString();
     StringAssert.Contains(htmlStr, " data-urlformat=\"" + AppPathModifier + "/articles/list/__id__",
         "Value of urlformat data attribute is incorrect");
 }
コード例 #55
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void HidePagerItemsAndCurrentPageIndexIs6_ShouldGenerateCorrectHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 6;
     IHtmlString html = _htmlHelper.Pager(_testList, new PagerOptions { PageIndexParameterName = "id", HidePagerItems = true });
     var attrs = new[]
     {
         "data-currentpage=\"6\"","data-firstpage=\"" + BaseLink + "\"",
         "data-invalidpageerrmsg=\"" + TestHelper.InvalidPageIndexErrorMessage + "\"",
         "data-outrangeerrmsg=\"" + TestHelper.PageIndexOutOfRangeErrorMessage + "\"",
         "data-pageparameter=\"id\"", "data-pagerid=\"Webdiyer.MvcPager\"", "data-pagecount=\"11\"",
         "data-urlformat=\"" + BaseLink + "/__id__\"","style=\"display:none\""
     };
     var sb = new StringBuilder("<div");
     foreach (var att in attrs.OrderBy(a => a))
     {
         sb.Append(" ").Append(att);
     }
     sb.Append("></div>");
     Assert.AreEqual(html.ToHtmlString(), TestHelper.CopyrightText + sb + TestHelper.CopyrightText);
 }
コード例 #56
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
        public void MultipleMvcPager_ShouldGenerateCorrectUrlForDataAttributesAndLinks()
        {
            _htmlHelper = TestHelper.GetHtmlHelper();
            _testList.CurrentPageIndex = 6;
            IHtmlString html = _htmlHelper.Pager(_testList,
                                                   new PagerOptions
                                                       {
                                                           PageIndexParameterName = "id"
                                                       });
            var htmlStr = html.ToHtmlString();
            StringAssert.Contains(htmlStr, "<a href=\"" + BaseLink + "/4\">4</a>",
                          "Paging url of the first MvcPager is incorrect");
            StringAssert.Contains(htmlStr, " data-firstpage=\"" + BaseLink + "\"",
                          "Value of firstpage data attribute of the first MvcPager is incorrent");
            StringAssert.Contains(htmlStr, " data-urlformat=\"" + BaseLink + "/__id__",
                          "Value of urlformat data attribute of the first MvcPager is incorrect");

            var plist=new PagedList<int>(Enumerable.Range(1,33),3,5);
            html = _htmlHelper.Pager(plist, new PagerOptions { RouteName = "Default" });
            htmlStr = html.ToHtmlString();
            StringAssert.Contains(htmlStr, " data-firstpage=\"" + BaseLink + "/2\"",
                          "Value of firstpage data attribute of the second MvcPager is incorrent");
            StringAssert.Contains(htmlStr, " data-urlformat=\"" + BaseLink + "/2?pageindex=__pageindex__",
                "Value of urlformat data attribute of the second MvcPager is incorrect");
        }
コード例 #57
0
ファイル: HtmlPagerTest.cs プロジェクト: wlclass/MvcPager
 public void CurrentPagerItemTemplate_ShouldGenerateCorrentHtml()
 {
     _htmlHelper = TestHelper.GetHtmlHelper();
     _testList.CurrentPageIndex = 2;
     IHtmlString html = _htmlHelper.Pager(_testList,
                                            new PagerOptions
                                                {
                                                    PageIndexParameterName = "id",
                                                    CurrentPagerItemTemplate =
                                                        "<span class=\"current\">{0}</span>"
                                                });
     StringAssert.Contains(html.ToHtmlString(),"<span class=\"current\">2</span>");
 }
コード例 #58
0
 public static MvcHtmlString Pager(this HtmlHelper htmlHelper, IPagedList list, string labelPrevious, string labelNext)
 {
     return(htmlHelper.Pager(list.PageSize, list.PageIndex, list.TotalItemCount, labelPrevious, labelNext));
 }