本文整理汇总了C#中Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput类的典型用法代码示例。如果您正苦于以下问题:C# TagHelperOutput类的具体用法?C# TagHelperOutput怎么用?C# TagHelperOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TagHelperOutput类属于Microsoft.AspNetCore.Razor.TagHelpers命名空间,在下文中一共展示了TagHelperOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process_DoesNothingIfTagNameIsNull
public void Process_DoesNothingIfTagNameIsNull()
{
// Arrange
var tagHelperOutput = new TagHelperOutput(
tagName: null,
attributes: new TagHelperAttributeList
{
{ "href", "~/home/index.html" }
},
getChildContentAsync: (useCachedResult, encoder) => Task.FromResult<TagHelperContent>(null));
var tagHelper = new UrlResolutionTagHelper(Mock.Of<IUrlHelperFactory>(), new HtmlTestEncoder());
var context = new TagHelperContext(
allAttributes: new TagHelperAttributeList(
Enumerable.Empty<TagHelperAttribute>()),
items: new Dictionary<object, object>(),
uniqueId: "test");
// Act
tagHelper.Process(context, tagHelperOutput);
// Assert
var attribute = Assert.Single(tagHelperOutput.Attributes);
Assert.Equal("href", attribute.Name, StringComparer.Ordinal);
var attributeValue = Assert.IsType<string>(attribute.Value);
Assert.Equal("~/home/index.html", attributeValue, StringComparer.Ordinal);
}
示例2: 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();
}
示例3: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var builder = new TagBuilder("img");
builder.Attributes["src"] = "/pictures/" + UrlHelperThumbnailExtensions.GetThumbnail(null, Src, Size);
output.MergeAttributes(builder);
}
示例4: TagHelperExecutionContext
/// <summary>
/// Instantiates a new <see cref="TagHelperExecutionContext"/>.
/// </summary>
/// <param name="tagName">The HTML tag name in the Razor source.</param>
/// <param name="tagMode">HTML syntax of the element in the Razor source.</param>
/// <param name="items">The collection of items used to communicate with other
/// <see cref="ITagHelper"/>s</param>
/// <param name="uniqueId">An identifier unique to the HTML element this context is for.</param>
/// <param name="executeChildContentAsync">A delegate used to execute the child content asynchronously.</param>
/// <param name="startTagHelperWritingScope">
/// A delegate used to start a writing scope in a Razor page and optionally override the page's
/// <see cref="HtmlEncoder"/> within that scope.
/// </param>
/// <param name="endTagHelperWritingScope">A delegate used to end a writing scope in a Razor page.</param>
public TagHelperExecutionContext(
string tagName,
TagMode tagMode,
IDictionary<object, object> items,
string uniqueId,
Func<Task> executeChildContentAsync,
Action<HtmlEncoder> startTagHelperWritingScope,
Func<TagHelperContent> endTagHelperWritingScope)
{
if (startTagHelperWritingScope == null)
{
throw new ArgumentNullException(nameof(startTagHelperWritingScope));
}
if (endTagHelperWritingScope == null)
{
throw new ArgumentNullException(nameof(endTagHelperWritingScope));
}
_tagHelpers = new List<ITagHelper>();
_allAttributes = new TagHelperAttributeList();
Context = new TagHelperContext(_allAttributes, items, uniqueId);
Output = new TagHelperOutput(tagName, new TagHelperAttributeList(), GetChildContentAsync)
{
TagMode = tagMode
};
Reinitialize(tagName, tagMode, items, uniqueId, executeChildContentAsync);
_startTagHelperWritingScope = startTagHelperWritingScope;
_endTagHelperWritingScope = endTagHelperWritingScope;
}
示例5: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var request = ViewContext.HttpContext.Request;
var result = await Prerenderer.RenderToString(
_applicationBasePath,
_nodeServices,
new JavaScriptModuleExport(ModuleName)
{
ExportName = ExportName,
WebpackConfig = WebpackConfigPath
},
request.GetEncodedUrl(),
request.Path + request.QueryString.Value,
CustomDataParameter);
output.Content.SetHtmlContent(result.Html);
// Also attach any specified globals to the 'window' object. This is useful for transferring
// general state between server and client.
if (result.Globals != null)
{
var stringBuilder = new StringBuilder();
foreach (var property in result.Globals.Properties())
{
stringBuilder.AppendFormat("window.{0} = {1};",
property.Name,
property.Value.ToString(Formatting.None));
}
if (stringBuilder.Length > 0)
{
output.PostElement.SetHtmlContent($"<script>{stringBuilder}</script>");
}
}
}
示例6: DefaultServerAutocompleteProcessor
public DefaultServerAutocompleteProcessor(TagHelperContext context, TagHelperOutput output, AutocompleteTagHelper tag, AutocompleteOptions options)
{
this.context = context;
this.output = output;
this.tag = tag;
this.options = options;
}
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:7,代码来源:DefaultServerAutocompleteProcessor.cs
示例7: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (MakePretty.HasValue && !MakePretty.Value)
{
return;
}
if (output.TagName == null)
{
// Another tag helper e.g. TagHelperviewComponentTagHelper has suppressed the start and end tags.
return;
}
string prettyStyle;
if (PrettyTagStyles.TryGetValue(output.TagName, out prettyStyle))
{
var style = Style ?? string.Empty;
if (!string.IsNullOrEmpty(style))
{
style += ";";
}
output.Attributes.SetAttribute("style", style + prettyStyle);
}
}
示例8: Process
/// <inheritdoc />
/// <remarks>Does nothing if <see cref="For"/> is <c>null</c>.</remarks>
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
var tagBuilder = Generator.GenerateTextArea(
ViewContext,
For.ModelExplorer,
For.Name,
rows: 0,
columns: 0,
htmlAttributes: null);
if (tagBuilder != null)
{
// Overwrite current Content to ensure expression result round-trips correctly.
output.Content.SetHtmlContent(tagBuilder.InnerHtml);
output.MergeAttributes(tagBuilder);
}
}
示例9: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (DisplayProperty == null && (DisplayPropertyExplorer == null || DisplayPropertyExpressionOverride==null))
new ArgumentNullException("display-property/display-expression-override+display-explorer");
if (For == null && (ForPropertyExplorer == null || ForExpressionOverride == null))
new ArgumentNullException("asp-for/for-expression-override+for-explorer");
if (string.IsNullOrWhiteSpace(ItemsDisplayProperty)) new ArgumentNullException("items-display-property");
if (string.IsNullOrWhiteSpace(ItemsValueProperty)) new ArgumentNullException("items-value-property");
if (string.IsNullOrWhiteSpace(ItemsUrl)) new ArgumentNullException("items-url");
if (string.IsNullOrWhiteSpace(UrlToken)) new ArgumentNullException("url-token");
if (string.IsNullOrWhiteSpace(DataSetName)) new ArgumentNullException("dataset-name");
if (MaxResults == 0) MaxResults=20;
if (MinChars == 0) MinChars = 3;
var currProvider = ViewContext.TagHelperProvider();
var resolver = jsonOptions.SerializerSettings.ContractResolver as DefaultContractResolver;
var vd = ViewContext.ViewData;
var options = new AutocompleteOptions
{
Generator = generator,
PropertyResolver = resolver != null ? resolver.GetResolvedPropertyName : new Func<string, string>(x => x),
ForcedValueName = currProvider.GenerateNames ? vd.GetFullHtmlFieldName(ForExpressionOverride ?? For.Name) : null,
ForcedDisplayName = currProvider.GenerateNames ? vd.GetFullHtmlFieldName(DisplayPropertyExpressionOverride ?? DisplayProperty.Name) : null,
NoId= !currProvider.GenerateNames || ViewContext.IsFilterRendering()
};
await currProvider.GetTagProcessor(TagName)(context, output, this, options, null);
}
示例10: DefaultServerGridProcessor
public DefaultServerGridProcessor(TagHelperContext context, TagHelperOutput output, GridTagHelper tag, GridOptions options, ContextualizedHelpers helpers)
{
this.context = context; this.output = output; this.tag = tag;
this.options = options; this.helpers = helpers;
basePrefix = tag.For.Name;
AdjustColumns();
}
开发者ID:MvcControlsToolkit,项目名称:MvcControlsToolkit.ControlsCore,代码行数:7,代码来源:DefaultServerGridProcessor.cs
示例11: 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);
}
示例12: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (ShowIfNull != null)
{
output.SuppressOutput();
}
}
示例13: 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);
}
示例14: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "select";
output.TagMode = TagMode.StartTagAndEndTag;
output.AppendClass("form-control");
var optionsList = new List<TagBuilder>();
if (Items == null)
{
Items = new List<SelectListItem>();
}
foreach (var item in Items)
{
var option = new TagBuilder("option");
option.Attributes.Add("value", item.Value);
option.InnerHtml.Append(item.Text);
optionsList.Add(option);
}
optionsList.ForEach(o =>
{
output.Content.AppendHtml(o);
});
base.Process(context, output);
}
示例15: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var urlHelper = urlHelperFactory.GetUrlHelper(ViewContext);
await Task.Run(() =>
{
output.TagMode = TagMode.SelfClosing;
output.TagName = null;
var speaker = speakerRepository.All.FirstOrDefault(_ => _.Name == Name);
if (speaker == null)
{
output.Content.SetHtmlContent($"<label>{Name}</label>");
}
else
{
output.Content.SetHtmlContent($"<a href=\"{urlHelper.Link("SpeakerDetails", new { name = Name })}\">{Name}</a>");
}
});
}