public static async Task <string> GetGeneratedContent(this ITagHelper tagHelper, HtmlEncoder htmlEncoder, string tagName, TagMode tagMode, TagHelperAttributeList attributes = null) { if (attributes == null) { attributes = new TagHelperAttributeList(); } TagHelperOutput output = new TagHelperOutput(tagName, attributes, (arg1, arg2) => { return(Task.Run <TagHelperContent>(() => new DefaultTagHelperContent())); }) { TagMode = tagMode }; TagHelperContext context = new TagHelperContext(attributes, new Dictionary <object, object>(), Guid.NewGuid().ToString()); tagHelper.Init(context); await tagHelper.ProcessAsync(context, output); using (var writer = new StringWriter()) { output.WriteTo(writer, htmlEncoder); return(writer.ToString()); } }
public static async Task RunTagHelperAsync(this ITagHelper tagHelper, Options options) { if (options.Context == null) { options.Context = new TagHelperContext(new TagHelperAttributeList(), new Dictionary <object, object>(), Guid.NewGuid().ToString("N")); } if (options.Attributes == null) { options.Attributes = new List <TagHelperAttribute>(); } if (options.TagName == null) { options.TagName = tagHelper.GetTagName(); } var output = new TagHelperOutput(options.TagName, new TagHelperAttributeList(options.Attributes), (b, e) => Task.Factory.StartNew(() => options.Content)) { TagMode = options.TagMode }; if (options.InitTagHelper) { tagHelper.Init(options.Context); } await tagHelper.ProcessAsync(options.Context, output); }
protected async Task <string> RenderTagHelperAsync(string tagName, TagMode tagMode, ITagHelper tagHelper, TagHelperAttributeList tagHelperAttributes = null) { if (tagHelperAttributes == null) { tagHelperAttributes = new TagHelperAttributeList(); } TagHelperOutput output = new TagHelperOutput(tagName, tagHelperAttributes, (useCachedResult, encoder) => { return(Task.Run <TagHelperContent>(() => new DefaultTagHelperContent())); }) { TagMode = tagMode, }; TagHelperContext context = new TagHelperContext(tagHelperAttributes, new Dictionary <object, object>(), Guid.NewGuid().ToString()); tagHelper.Init(context); await tagHelper.ProcessAsync(context, output); return(output.RenderTag()); }
private async Task <string> GetGeneratedContentFromTagHelper(string tagName, TagMode tagMode, ITagHelper tagHelper, TagHelperAttributeList attributes = null) { if (attributes == null) { attributes = new TagHelperAttributeList(); } TagHelperOutput output = new TagHelperOutput(tagName, attributes, (arg1, arg2) => { return(Task.Run <TagHelperContent>(() => new DefaultTagHelperContent())); }) { TagMode = tagMode }; TagHelperContext context = new TagHelperContext(attributes, new Dictionary <object, object>(), Guid.NewGuid().ToString()); tagHelper.Init(context); await tagHelper.ProcessAsync(context, output); return(output.RenderTag(_htmlEncoder)); }