我在以下代码中定义了一个自定义 TagHelper:
namespace TJ.Website.Core.TagHelpers {
[HtmlTargetElement("pager", Attributes = "total-pages, current-page, link-url")]
public class PagerTagHelper : TagHelper {
public int CurrentPage { get; set; }
public int TotalPages { get; set; }
[HtmlAttributeName("link-url")]
public string Url { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output) {
output.TagName = "div";
output.PreContent.SetContent("<ul class=\"link-list\">");
var items = new StringBuilder();
for (var i = 1; i <= TotalPages; i++) {
var li = new TagBuilder("li");
var a = new TagBuilder("a");
a.MergeAttribute("href", $"{Url}?page={i}");
a.MergeAttribute("title", $"Click to go to page {i}");
a.InnerHtml.Append(i.ToString());
if (i == CurrentPage) {
a.AddCssClass("active");
}
li.InnerHtml.Append(a.InnerHtml.ToString());
items.AppendLine(li.ToString());
}
output.Content.SetContent(items.ToString());
output.PostContent.SetContent("</ul>");
output.Attributes.Clear();
output.Attributes.Add("class", "pager");
}
}
}
这是我的 _ViewImports.cs.html 页面
@using TJ.Website.Core
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@addTagHelper *, TJ.Website.Core
@inject Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration TelemetryConfiguration
在我看来Views\Home\Index.cshtml
,我想这样做
<pager total-pages='6' current-page='1'></pager>
但它没有呈现.../在我看来我的程序集/项目名称是 TJ.Website.Core
请帮忙