private async Task <TabTagHelper> ConvertToTagHelper(TabItem item) { var tagHelper = new TabTagHelper { ViewContext = TabStrip.ViewContext, Selected = item.Selected, Disabled = !item.Enabled, Visible = item.Visible, Ajax = item.Ajax, Title = item.Text, Name = item.Name, BadgeStyle = (BadgeStyle)item.BadgeStyle, BadgeText = item.BadgeText, Icon = item.Icon, ImageUrl = item.ImageUrl, Summary = item.Summary }; // Create TagHelperContext for tab passing it parent context's items dictionary (that's what Razor does) var context = new TagHelperContext("tab", new TagHelperAttributeList(), Context.Items, CommonHelper.GenerateRandomDigitCode(10)); // Must init tab, otherwise "Tabs" list is empty inside tabstrip helper. tagHelper.Init(context); var outputAttrList = new TagHelperAttributeList(); item.HtmlAttributes.CopyTo(outputAttrList); item.LinkHtmlAttributes.CopyTo(outputAttrList); if (!item.HasContent && item.HasRoute) { outputAttrList.Add("href", item.GenerateUrl(tagHelper.UrlHelper)); } var output = new TagHelperOutput("tab", outputAttrList, async(_, _) => { var content = item.HasContent ? await item.GetContentAsync(tagHelper.ViewContext) : HtmlString.Empty; var contentTag = new TagBuilder("div"); contentTag.MergeAttributes(item.ContentHtmlAttributes, false); TagHelperContent tabContent = new DefaultTagHelperContent() .AppendHtml(contentTag.Attributes.Count > 0 ? contentTag.RenderStartTag() : HtmlString.Empty) .AppendHtml(content) .AppendHtml(contentTag.Attributes.Count > 0 ? contentTag.RenderEndTag() : HtmlString.Empty); return(tabContent); }); // Process tab await tagHelper.ProcessAsync(context, output); return(tagHelper); }
/// <summary> /// 测试初始化 /// </summary> public TabTagHelperTest(ITestOutputHelper output) { _output = output; _component = new TabTagHelper(); }