本文整理汇总了C#中Microsoft.AspNet.Razor.TagHelpers.TagHelperContext类的典型用法代码示例。如果您正苦于以下问题:C# TagHelperContext类的具体用法?C# TagHelperContext怎么用?C# TagHelperContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TagHelperContext类属于Microsoft.AspNet.Razor.TagHelpers命名空间,在下文中一共展示了TagHelperContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
//if no scripts were added, suppress the contents
if (!_httpContextAccessor.HttpContext.Items.ContainsKey(InlineScriptConcatenatorTagHelper.ViewDataKey))
{
output.SuppressOutput();
return;
}
//Otherwise get all the scripts for the page
var scripts =
_httpContextAccessor.HttpContext.Items[InlineScriptConcatenatorTagHelper.ViewDataKey] as
IDictionary<string, NamedScriptInfo>;
if (null == scripts)
{
output.SuppressOutput();
return;
}
//Concatenate all of them and set them as the contents of this tag
var allScripts = string.Join("\r\n", OrderedScripts(scripts.Values).Select(os => os.Script));
output.TagMode = TagMode.StartTagAndEndTag;
//HACK:Need to figure out how to get rid of the script tags for the placeholder element
allScripts = $"</script><!--Rendered Scripts Output START-->\r\n{allScripts}\r\n</script><!--Rendered Scripts Output END--><script>";//HACK:ugly
var unminifiedContent = output.Content.SetHtmlContent(allScripts);
Debug.WriteLine(unminifiedContent.GetContent());
//TODO:Impliment dynamic minification (Assuming that some scenarios will be sped up, and others slowed down. Leave choice to user)
}
开发者ID:SvdSinner,项目名称:ScriptManagerPlus,代码行数:28,代码来源:InlineScriptTagHelper.cs
示例2: 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["style"] = style + prettyStyle;
}
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:26,代码来源:PrettyTagHelper.cs
示例3: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
StringBuilder sb = new StringBuilder();
string menuUrl = _UrlHelper.Action(ActionName, ControllerName, new { Area = AreaName });
if (string.IsNullOrEmpty(menuUrl))
throw new InvalidOperationException(string.Format("Can not find URL for {0}.{1}", ControllerName, ActionName));
output.TagName = "li";
var a = new TagBuilder("a");
a.MergeAttribute("href", $"{menuUrl}");
a.MergeAttribute("title", MenuText);
a.InnerHtml.Append(MenuText);
var routeData = ViewContext.RouteData.Values;
var currentController = routeData["controller"];
var currentAction = routeData["action"];
var currentArea = routeData.ContainsKey("area") ? routeData["area"] : string.Empty;
if (string.Equals(ActionName, currentAction as string, StringComparison.OrdinalIgnoreCase)
&& string.Equals(ControllerName, currentController as string, StringComparison.OrdinalIgnoreCase)
&& string.Equals(AreaName, currentArea as string, StringComparison.OrdinalIgnoreCase))
{
output.Attributes.Add("class", "active");
}
output.Content.SetContent(a);
}
开发者ID:AugustinasNomicas,项目名称:BookingSystem,代码行数:30,代码来源:MenuLinkTagHelper.cs
示例4: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var surroundingTagName = Surround.ToLowerInvariant();
output.PreElement.AppendHtml($"<{surroundingTagName}>");
output.PostElement.AppendHtml($"</{surroundingTagName}>");
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:7,代码来源:SurroundTagHelper.cs
示例5: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (ShowIfNull != null)
{
output.SuppressOutput();
}
}
开发者ID:pugillum,项目名称:AspNet5IdentityServerAngularImplicitFlow,代码行数:7,代码来源:HideShowTagHelpers.cs
示例6: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "div";
if (output.Attributes["class"].IsNull())
{
output.Attributes["class"] = "item";
}
else
{
output.Attributes["class"].Value += " item";
}
/*
<div class="item">
<i class="marker icon"></i>
<div class="content">@Html.DisplayFor(x => item.FullAddress)</div>
</div>
*/
var html = new StringBuilder();
html.Append($"<i class='{Icon} icon'></i>");
html.Append($"<div class='content'>{Content}</div>");
var childContent = output.GetChildContentAsync();
output.Content.SetHtmlContent(html.ToString());
}
开发者ID:RR-Studio,项目名称:RealEstateCrm,代码行数:27,代码来源:UiListItem.cs
示例7: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var request = this.contextAccessor.HttpContext.Request;
var result = await Prerenderer.RenderToString(
applicationBasePath: this.applicationBasePath,
nodeServices: this.nodeServices,
bootModule: new JavaScriptModuleExport(this.ModuleName) {
exportName = this.ExportName,
webpackConfig = this.WebpackConfigPath
},
requestAbsoluteUrl: UriHelper.GetEncodedUrl(this.contextAccessor.HttpContext.Request),
requestPathAndQuery: request.Path + request.QueryString.Value);
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.ToString() }</script>");
}
}
}
开发者ID:jimitndiaye,项目名称:NodeServices,代码行数:28,代码来源:PrerenderTagHelper.cs
示例8: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var localizer = Localizer ?? GetViewLocalizer();
var aspLocAttr = output.Attributes["asp-loc"];
if (aspLocAttr != null)
{
var resourceKey = aspLocAttr.Minimized
? (await output.GetChildContentAsync()).GetContent()
: aspLocAttr.Value.ToString();
output.Content.SetContent(localizer.GetHtml(resourceKey));
output.Attributes.Remove(aspLocAttr);
}
var localizeAttributes = output.Attributes.Where(attr => attr.Name.StartsWith("asp-loc-", StringComparison.OrdinalIgnoreCase)).ToList();
foreach (var attribute in localizeAttributes)
{
var attributeToLocalize = output.Attributes[attribute.Name.Substring("asp-loc-".Length)];
if (attributeToLocalize != null)
{
var resourceKey = attribute.Minimized
? attributeToLocalize.Value.ToString()
: attribute.Value.ToString();
attributeToLocalize.Value = localizer.GetHtml(resourceKey);
}
output.Attributes.Remove(attribute);
}
}
开发者ID:leloulight,项目名称:Entropy,代码行数:30,代码来源:LocalizationTagHelper.cs
示例9: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var specified = context?.AllAttributes[ImagesAttributeName]?.Name == ImagesAttributeName &&
Images != null && Images.Any();
if (specified)
{
string classValue;
classValue = output.Attributes.ContainsName("class")
? string.Format("{0} {1}", output.Attributes["class"], "lazyload")
: "lazyload";
output.Attributes["class"] = classValue;
var images = Images.ToList();
if (images.Count == 1)
{
output.Attributes.Add("data-src", images[0]?.Url);
}
else
{
output.Attributes.Add("data-sizes", "auto");
List<string> sizes = new List<string>();
foreach (var image in images)
{
sizes.Add(MakePath(image.Url, image.Width));
}
output.Attributes.Add("data-srcset", string.Join(",", sizes));
}
}
else
{
base.Process(context, output);
}
}
开发者ID:scanham,项目名称:FlatplanRenderer,代码行数:35,代码来源:LazySizesTagHelper.cs
示例10: 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.Append(labelBuilder);
}
output.Content.Append(contentDiv);
base.Process(context, output);
}
开发者ID:neutmute,项目名称:steelcap,代码行数:31,代码来源:FormGroupTagHelper.cs
示例11: 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)
{
foreach (var content in formContext.EndOfFormContent)
{
output.PostContent.Append(content);
}
}
// Reset the FormContext
ViewContext.FormContext = null;
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:27,代码来源:RenderAtEndOfFormTagHelper.cs
示例12: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
TagBuilder table = new TagBuilder("table");
table.GenerateId(context.UniqueId, "id");
var attributes = context.AllAttributes.Where(a => a.Name != ItemsAttributeName).ToDictionary(a => a.Name);
table.MergeAttributes(attributes);
var tr = new TagBuilder("tr");
var heading = Items.First();
PropertyInfo[] properties = heading.GetType().GetProperties();
foreach (var prop in properties)
{
var th = new TagBuilder("th");
th.InnerHtml.Append(prop.Name);
tr.InnerHtml.Append(th);
}
table.InnerHtml.Append(tr);
foreach (var item in Items)
{
tr = new TagBuilder("tr");
foreach (var prop in properties)
{
var td = new TagBuilder("td");
td.InnerHtml.Append(prop.GetValue(item).ToString());
tr.InnerHtml.Append(td);
}
table.InnerHtml.Append(tr);
}
output.Content.Append(table.InnerHtml);
}
开发者ID:CNinnovation,项目名称:TechConference2016,代码行数:34,代码来源:TableTagHelper.cs
示例13: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
(HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);
var content = await output.GetChildContentAsync();
output.Content.SetContent(HtmlHelper.Hidden(Name, content.GetContent(HtmlEncoder)));
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:7,代码来源:HiddenTagHelper.cs
示例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.Append(o);
});
base.Process(context, output);
}
开发者ID:neutmute,项目名称:steelcap,代码行数:30,代码来源:DropdownTagHelper.cs
示例15: Process
/// <inheritdoc />
/// <remarks>Does nothing if <see cref="ValidationSummary"/> is <see cref="ValidationSummary.None"/>.</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));
}
if (ValidationSummary == ValidationSummary.None)
{
return;
}
var tagBuilder = Generator.GenerateValidationSummary(
ViewContext,
excludePropertyErrors: ValidationSummary == ValidationSummary.ModelOnly,
message: null,
headerTag: null,
htmlAttributes: null);
if (tagBuilder != null)
{
output.MergeAttributes(tagBuilder);
output.PostContent.Append(tagBuilder.InnerHtml);
}
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:31,代码来源:ValidationSummaryTagHelper.cs
示例16: Init
public override void Init(TagHelperContext context)
{
base.Init(context);
FormGroupContext = context.GetFormGroupContext();
FormContext = context.GetFormContext();
Size = Size ?? FormContext?.ControlSize;
}
开发者ID:Pietervdw,项目名称:BootstrapTagHelpers,代码行数:7,代码来源:SelectTagHelper.cs
示例17: Init
/// <inheritdoc />
public override void Init(TagHelperContext context)
{
if (context == null)
{
throw new ArgumentNullException(nameof(context));
}
// Note null or empty For.Name is allowed because TemplateInfo.HtmlFieldPrefix may be sufficient.
// IHtmlGenerator will enforce name requirements.
if (For.Metadata == null)
{
throw new InvalidOperationException(Resources.FormatTagHelpers_NoProvidedMetadata(
"<select>",
ForAttributeName,
nameof(IModelMetadataProvider),
For.Name));
}
// Base allowMultiple on the instance or declared type of the expression to avoid a
// "SelectExpressionNotEnumerable" InvalidOperationException during generation.
// Metadata.IsEnumerableType is similar but does not take runtime type into account.
var realModelType = For.ModelExplorer.ModelType;
_allowMultiple = typeof(string) != realModelType &&
typeof(IEnumerable).GetTypeInfo().IsAssignableFrom(realModelType.GetTypeInfo());
_currentValues = Generator.GetCurrentValues(
ViewContext,
For.ModelExplorer,
expression: For.Name,
allowMultiple: _allowMultiple);
// Whether or not (not being highly unlikely) we generate anything, could update contained <option/>
// elements. Provide selected values for <option/> tag helpers.
context.Items[typeof(SelectTagHelper)] = _currentValues;
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:35,代码来源:SelectTagHelper.cs
示例18: BootstrapProcess
protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) {
if (PrevText == null)
PrevText = Ressources.Previous;
if (NextText == null)
NextText = Ressources.Next;
output.TagName = "nav";
var content = "<ul class=\"pager\"><li";
if (PrevDisabled && Stretch)
content += " class=\"previous disabled\"><a>";
else if (PrevDisabled)
content += " class=\"disabled\"><a>";
else if (Stretch)
content += $" class=\"previous\"><a href=\"{PrevHref}\">";
else
content += $"><a href=\"{PrevHref}\">";
if (!HideArrows)
content += "<span aria-hidden=\"true\">←</span> ";
content += PrevText + "</a></li><li";
if (NextDisabled && Stretch)
content += " class=\"next disabled\"><a>";
else if (NextDisabled)
content += " class=\"disabled\"><a>";
else if (Stretch)
content += $" class=\"next\"><a href=\"{NextHref}\">";
else
content += $"><a href=\"{NextHref}\">";
content += NextText;
if (!HideArrows)
content += " <span aria-hidden=\"true\">→</span>";
content += "</a></li></ul>";
output.Content.SetHtmlContent(content);
}
开发者ID:Pietervdw,项目名称:BootstrapTagHelpers,代码行数:32,代码来源:PagerTagHelper.cs
示例19: BootstrapProcess
protected override void BootstrapProcess(TagHelperContext context, TagHelperOutput output) {
if (HiddenXs)
output.AddCssClass("hidden-xs");
if (HiddenSm)
output.AddCssClass("hidden-sm");
if (HiddenMd)
output.AddCssClass("hidden-md");
if (HiddenLg)
output.AddCssClass("hidden-lg");
if (HiddenPrint)
output.AddCssClass("hidden-print");
if (SrOnly || SrOnlyFocusable)
output.AddCssClass("sr-only");
if (SrOnlyFocusable)
output.AddCssClass("sr-only-focusable");
if (VisibleXs != null)
output.AddCssClass("visible-xs-" + VisibleXs.Value.GetDescription());
if (VisibleSm != null)
output.AddCssClass("visible-sm-" + VisibleSm.Value.GetDescription());
if (VisibleMd != null)
output.AddCssClass("visible-md-" + VisibleMd.Value.GetDescription());
if (VisibleLg != null)
output.AddCssClass("visible-lg-" + VisibleLg.Value.GetDescription());
if (VisiblePrint != null)
output.AddCssClass("visible-print-" + VisiblePrint.Value.GetDescription());
}
开发者ID:Pietervdw,项目名称:BootstrapTagHelpers,代码行数:26,代码来源:ResponsiveUtilitiesTagHelper.cs
示例20: Process_ResolvesTildeSlashValues
public void Process_ResolvesTildeSlashValues(object url, object expectedHref)
{
// Arrange
var tagHelperOutput = new TagHelperOutput(
tagName: "a",
attributes: new TagHelperAttributeList
{
{ "href", url }
},
getChildContentAsync: _ => Task.FromResult<TagHelperContent>(null));
var urlHelperMock = new Mock<IUrlHelper>();
urlHelperMock
.Setup(urlHelper => urlHelper.Content(It.IsAny<string>()))
.Returns(new Func<string, string>(value => "/approot" + value.Substring(1)));
var tagHelper = new UrlResolutionTagHelper(urlHelperMock.Object, new TestHtmlEncoder());
var context = new TagHelperContext(
allAttributes: new ReadOnlyTagHelperAttributeList<IReadOnlyTagHelperAttribute>(
Enumerable.Empty<IReadOnlyTagHelperAttribute>()),
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);
Assert.IsType(expectedHref.GetType(), url);
Assert.Equal(expectedHref.ToString(), attribute.Value.ToString());
Assert.False(attribute.Minimized);
}
开发者ID:huoxudong125,项目名称:Mvc,代码行数:32,代码来源:UrlResolutionTagHelperTest.cs
注:本文中的Microsoft.AspNet.Razor.TagHelpers.TagHelperContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论