说明

自定义一个类继承TagHelper,注意自定义类的 必须以TagHelper结尾,这个有点类是属性 Attribute的写法

protected TagHelper();

        //
        // 摘要:
        //     When a set of Microsoft.AspNetCore.Razor.TagHelpers.ITagHelpers are executed,
        //     their Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.Init(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext)'s
        //     are first invoked in the specified Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.Order;
        //     then their Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext,Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput)'s
        //     are invoked in the specified Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.Order.
        //     Lower values are executed first.
        //
        // 备注:
        //     Default order is 0.
        public virtual int Order { get; }

        //
        // 摘要:
        //     Initializes the Microsoft.AspNetCore.Razor.TagHelpers.ITagHelper with the given
        //     context. Additions to Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext.Items
        //     should be done within this method to ensure they're added prior to executing
        //     the children.
        //
        // 参数:
        //   context:
        //     Contains information associated with the current HTML tag.
        //
        // 备注:
        //     When more than one Microsoft.AspNetCore.Razor.TagHelpers.ITagHelper runs on the
        //     same element, TagHelperOutput.GetChildContentAsync may be invoked prior to Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext,Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput).
        public virtual void Init(TagHelperContext context);
        //
        // 摘要:
        //     Synchronously executes the Microsoft.AspNetCore.Razor.TagHelpers.TagHelper with
        //     the given context and output.
        //
        // 参数:
        //   context:
        //     Contains information associated with the current HTML tag.
        //
        //   output:
        //     A stateful HTML element used to generate an HTML tag.
        public virtual void Process(TagHelperContext context, TagHelperOutput output);
        //
        // 摘要:
        //     Asynchronously executes the Microsoft.AspNetCore.Razor.TagHelpers.TagHelper with
        //     the given context and output.
        //
        // 参数:
        //   context:
        //     Contains information associated with the current HTML tag.
        //
        //   output:
        //     A stateful HTML element used to generate an HTML tag.
        //
        // 返回结果:
        //     A System.Threading.Tasks.Task that on completion updates the output.
        //
        // 备注:
        //     By default this calls into Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.Process(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext,Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput).
        public virtual Task ProcessAsync(TagHelperContext context, TagHelperOutput output);

 重写一个 ProcessAsync 这里我以异步为例子

首先说明下分页需要的重要参数 定义一个分页参数类

 public class PagerOptions
    {
       
        
        /// <summary>
        /// 每页数据条数
        /// </summary>
        public int PageSize { get; set; }
        /// <summary>
        /// 当前页码
        /// </summary>
        public int CurrentPageIndex { get; set; }
        /// <summary>
        /// 数据总条数
        /// </summary>
        public int ItemTotal { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int PageTotal
        {
            get
            {
                return ItemTotal % PageSize > 0 ? ItemTotal / PageSize + 1 : ItemTotal / PageSize;
            }
        }
        /// <summary>
        /// 显示的页面个数(只显示5个页码)
        /// </summary>
        public int EveryCount { get; set; }
        /// <summary>
        /// 允许选择页码
        /// </summary>
        public bool IsSelectPageSize { get; set; }
        /// <summary>
        /// 每页数据条数范围 
        /// </summary>
        public int[] SelectPageSize { get; set; }
        /// <summary>
        /// 是否显示转到页码
        /// </summary>
        public bool IsGoPage { get; set; }
        /// <summary>
        /// 分页访问地址
        /// </summary>
        public string PageUri { get; set; }
    }
PagerOptions

相关文章: