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 (DataSource == null)
            {
                throw new ArgumentNullException(nameof(DataSource));
            }
            int actualPageCount = (int)Math.Ceiling(DataSource.TotalItemCount / (double)DataSource.PageSize);

            _pageIndex = DataSource.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);

            //output.PreElement.SetHtmlContent(_copyrightText);
            //output.TagName = TagName;
            //_content = new DefaultTagHelperContent();
            //output.Content = _content.SetHtmlContent(buildPager(output));
            //output.PostElement.SetHtmlContent(_copyrightText);
        }
Beispiel #2
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);
        }