Esempio n. 1
0
        public void WriteTo(TextWriter writer, HtmlEncoder encoder)
        {
            if (writer == null)
            {
                throw new ArgumentNullException(nameof(writer));
            }
            var totalPageCount   = (int)Math.Ceiling(_totalItemCount / (double)_pageSize);
            var urlHelperFactory = _htmlHelper.ViewContext.HttpContext.RequestServices.GetRequiredService <IUrlHelperFactory>();
            var urlHelper        = urlHelperFactory.GetUrlHelper(_htmlHelper.ViewContext);
            var pager            = new PagerBuilder(_htmlHelper.ViewContext, urlHelper, totalPageCount, _currentPageIndex, _pagerOptions);

            writer.Write(pager.GenerateHtml());
        }
        public override void Process(TagHelperContext context, TagHelperOutput output)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            if (output == null)
            {
                throw new ArgumentNullException(nameof(output));
            }

            //if(!int.TryParse((string)ViewContext.RouteData.Values[PageIndexParameterName],out _pageIndex)){
            //    _pageIndex = 1;
            //}

            if (Model == null)
            {
                throw new ArgumentNullException(nameof(Model));
            }
            int actualPageCount = (int)Math.Ceiling(Model.TotalItemCount / (double)Model.PageSize);

            _pageIndex = Model.CurrentPageIndex;
            if (MaximumPageNumber == 0 || MaximumPageNumber > actualPageCount)
            {
                _totalPageCount = actualPageCount;
            }
            else
            {
                _totalPageCount = MaximumPageNumber;
            }

            PagerBuilder pb;

            if (AjaxEnabled)
            {
                pb = new PagerBuilder(ViewContext, _urlHelperFactory.GetUrlHelper(ViewContext), _totalPageCount, _pageIndex, Options, AjaxOptions);
            }
            else
            {
                pb = new PagerBuilder(ViewContext, _urlHelperFactory.GetUrlHelper(ViewContext), _totalPageCount, _pageIndex, Options);
            }
            var content = pb.GenerateHtml();

            output.TagName = string.Empty;
            output.Content = new DefaultTagHelperContent().SetHtmlContent(content);
        }
Esempio n. 3
0
        public IDictionary <string, object> ToUnobtrusiveHtmlAttributes()
        {
            var result = new Dictionary <string, object>
            {
                { "data-ajax", "true" },
            };

            PagerBuilder.AddToDictionaryIfNotEmpty(result, "data-ajax-method", HttpMethod);
            PagerBuilder.AddToDictionaryIfNotEmpty(result, "data-ajax-confirm", Confirm);
            PagerBuilder.AddToDictionaryIfNotEmpty(result, "data-ajax-begin", OnBegin);
            PagerBuilder.AddToDictionaryIfNotEmpty(result, "data-ajax-complete", OnComplete);
            PagerBuilder.AddToDictionaryIfNotEmpty(result, "data-ajax-failure", OnFailure);
            PagerBuilder.AddToDictionaryIfNotEmpty(result, "data-ajax-success", OnSuccess);

            if (!string.IsNullOrWhiteSpace(DataFormId))
            {
                result.Add("data-ajax-search-form", PagerBuilder.EscapeIdSelector(DataFormId));
            }
            if (!String.IsNullOrWhiteSpace(LoadingElementId))
            {
                result.Add("data-ajax-loading", PagerBuilder.EscapeIdSelector(LoadingElementId.Trim('#')));

                if (LoadingElementDuration > 0)
                {
                    result.Add("data-ajax-loading-duration", LoadingElementDuration);
                }
            }
            if (!String.IsNullOrWhiteSpace(UpdateTargetId))
            {
                result.Add("data-ajax-update", PagerBuilder.EscapeIdSelector(UpdateTargetId.Trim('#')));
            }
            if (EnablePartialLoading)
            {
                result.Add("data-ajax-partial-loading", "true");
            }
            if (!AllowCache)
            {
                result.Add("data-ajax-cache", "false");
            }
            if (!EnableHistorySupport)
            {
                result.Add("data-ajax-history", "false");
            }

            return(result);
        }