本文整理汇总了C#中Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput.GetChildContentAsync方法的典型用法代码示例。如果您正苦于以下问题:C# TagHelperOutput.GetChildContentAsync方法的具体用法?C# TagHelperOutput.GetChildContentAsync怎么用?C# TagHelperOutput.GetChildContentAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput
的用法示例。
在下文中一共展示了TagHelperOutput.GetChildContentAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessAsync
/// <inheritdoc />
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
IHtmlContent content = null;
// Create a cancellation token that will be used
// to release the task from the memory cache.
var tokenSource = new CancellationTokenSource();
if (Enabled)
{
var cacheKey = new CacheTagKey(this);
content = await _distributedCacheService.ProcessContentAsync(output, cacheKey, GetDistributedCacheEntryOptions());
}
else
{
content = await output.GetChildContentAsync();
}
// Clear the contents of the "cache" element since we don't want to render it.
output.SuppressOutput();
output.Content.SetHtmlContent(content);
}
示例2: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await output.GetChildContentAsync();
var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)];
modalContext.Body = childContent;
output.SuppressOutput();
}
示例3: Process
public override async void Process(TagHelperContext context, TagHelperOutput output)
{
var originalContent = await output.GetChildContentAsync();
output.AppendClass("form-group");
TagBuilder labelBuilder = null;
if (!originalContent.GetContent().Contains("<label"))
{
labelBuilder = FormGroupLabel.Get(Horizontal, LabelText);
}
var contentDiv = new TagBuilder("div");
if (Horizontal)
{
contentDiv.AddCssClass("col-sm-8");
}
contentDiv.InnerHtml.AppendHtml(originalContent.GetContent());
output.TagName = "div";
output.Content.Clear();
if (labelBuilder != null)
{
output.Content.AppendHtml(labelBuilder);
}
output.Content.AppendHtml(contentDiv);
base.Process(context, output);
}
示例4: GetContent
private async Task<string> GetContent(TagHelperOutput output)
{
if (Content == null)
return (await output.GetChildContentAsync()).GetContent();
return Content.Model?.ToString();
}
示例5: ProcessAsync
/// <inheritdoc />
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
await output.GetChildContentAsync();
var formContext = ViewContext.FormContext;
if (formContext.HasEndOfFormContent)
{
// Perf: Avoid allocating enumerator
for (var i = 0; i < formContext.EndOfFormContent.Count; i++)
{
output.PostContent.AppendHtml(formContext.EndOfFormContent[i]);
}
}
// Reset the FormContext
ViewContext.FormContext = new FormContext();
}
示例6: Process
public override async void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "div";
output.AppendClass("widget-box");
output.AppendClass(Class);
var originalContent = await output.GetChildContentAsync();
var innerHtml = originalContent.GetContent();
output.Content.Clear();
if (!innerHtml.Contains(WidgetBoxHeaderHelper.HeaderCss))
{
// user is taking easy/lazy way of declaring the widget box
output.Content.AppendHtml(WidgetBoxHeaderHelper.GetFullHeader(Title, IsCollapsible));
var widgetBodyDiv = WidgetBoxBodyHelper.GetFullBodyInternals(Padding, innerHtml);
output.Content.AppendHtml(widgetBodyDiv);
}
else
{
// user is doing the hardwork themselves
output.Content.AppendHtml(innerHtml);
}
base.Process(context, output);
}
示例7: GetChildContentAsync_CallsGetChildContentAsync
public async Task GetChildContentAsync_CallsGetChildContentAsync()
{
// Arrange
bool? passedUseCacheResult = null;
HtmlEncoder passedEncoder = null;
var content = new DefaultTagHelperContent();
var output = new TagHelperOutput(
tagName: "tag",
attributes: new TagHelperAttributeList(),
getChildContentAsync: (useCachedResult, encoder) =>
{
passedUseCacheResult = useCachedResult;
passedEncoder = encoder;
return Task.FromResult<TagHelperContent>(content);
});
// Act
var result = await output.GetChildContentAsync();
// Assert
Assert.True(passedUseCacheResult.HasValue);
Assert.True(passedUseCacheResult.Value);
Assert.Null(passedEncoder);
Assert.Same(content, result);
}
示例8: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "a";
var content = await output.GetChildContentAsync();
var address = content.GetContent() + "@" + _configuration.Domain;
output.Attributes.SetAttribute("href", "mailto:" + address);
output.Content.SetContent(address);
}
示例9: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "a"; // Replaces <email> with <a> tag
var content = await output.GetChildContentAsync();
var target = content.GetContent() + "@" + EmailDomain;
output.Attributes.SetAttribute("href", "mailto:" + target);
output.Content.SetContent(target);
}
示例10: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var defaultContent = await output.GetChildContentAsync();
output.Content
.SetHtmlContent("Default encoder: ")
.AppendHtml(defaultContent);
output.TagName = "pre";
}
示例11: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await output.GetChildContentAsync();
// Find Urls in the content and replace them with their anchor tag equivalent.
output.Content.SetHtmlContent(Regex.Replace(
childContent.GetContent(),
@"\b(?:https?://)(\S+)\b",
"<a target=\"_blank\" href=\"$0\">$0</a>")); // http link version}
}
示例12: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var content = await output.GetChildContentAsync();
var collectionContext = (InputCollectionContext)context.Items[typeof(InputCollectionTagHelper)];
var localContext = new InputCollectionItemContext() { Label = Label, Content = content };
collectionContext.Items.Add(localContext);
output.SuppressOutput();
}
示例13: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await output.GetChildContentAsync();
// Find Urls in the content and replace them with their anchor tag equivalent.
output.Content.AppendHtml(Regex.Replace(
childContent.GetContent(),
@"\b(?:https?://|www\.)(\S+)\b",
"<strong><a target=\"_blank\" href=\"http://$0\">$0</a></strong>"));
}
示例14: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = output.Content.IsModified ? output.Content.GetContent() :
(await output.GetChildContentAsync()).GetContent();
// Find Urls in the content and replace them with their anchor tag equivalent.
output.Content.SetHtmlContent(Regex.Replace(
childContent,
@"\b(www\.)(\S+)\b",
"<a target=\"_blank\" href=\"http://$0\">$0</a>")); // www version
}
示例15: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var nullContent = await output.GetChildContentAsync(NullHtmlEncoder.Default);
// Note this is very unsafe. Should always post-process content that may not be fully HTML encoded before
// writing it into a response. Here for example, could pass SetContent() a string and that would be
// HTML encoded later.
output.PostContent
.SetHtmlContent("<br />Null encoder: ")
.AppendHtml(nullContent);
}