本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperOutput.FindPrefixedAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# TagHelperOutput.FindPrefixedAttributes方法的具体用法?C# TagHelperOutput.FindPrefixedAttributes怎么用?C# TagHelperOutput.FindPrefixedAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperOutput
的用法示例。
在下文中一共展示了TagHelperOutput.FindPrefixedAttributes方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
/// <inheritdoc />
/// <remarks>
/// Does nothing if user provides an <c>action</c> attribute and <see cref="AntiForgery"/> is <c>null</c> or
/// <c>false</c>.
/// </remarks>
/// <exception cref="InvalidOperationException">
/// Thrown if <c>action</c> attribute is provided and <see cref="Action"/> or <see cref="Controller"/> are
/// non-<c>null</c> or if the user provided <c>asp-route-*</c> attributes.
/// </exception>
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var antiForgeryDefault = true;
var routePrefixedAttributes = output.FindPrefixedAttributes(RouteAttributePrefix);
// If "action" is already set, it means the user is attempting to use a normal <form>.
if (output.Attributes.ContainsKey(HtmlActionAttributeName))
{
if (Action != null || Controller != null || routePrefixedAttributes.Any())
{
// User also specified bound attributes we cannot use.
throw new InvalidOperationException(
Resources.FormatFormTagHelper_CannotOverrideAction(
"<form>",
HtmlActionAttributeName,
ActionAttributeName,
ControllerAttributeName,
RouteAttributePrefix));
}
// User is using the FormTagHelper like a normal <form> tag. Anti-forgery default should be false to
// not force the anti-forgery token on the user.
antiForgeryDefault = false;
}
else
{
var routeValues = GetRouteValues(output, routePrefixedAttributes);
var tagBuilder = Generator.GenerateForm(ViewContext,
Action,
Controller,
routeValues,
method: null,
htmlAttributes: null);
if (tagBuilder != null)
{
output.MergeAttributes(tagBuilder);
output.PostContent.Append(tagBuilder.InnerHtml);
}
}
if (AntiForgery ?? antiForgeryDefault)
{
var antiForgeryTagBuilder = Generator.GenerateAntiForgery(ViewContext);
if (antiForgeryTagBuilder != null)
{
output.PostContent.Append(antiForgeryTagBuilder.ToString(TagRenderMode.SelfClosing));
}
}
}
示例2: Process
/// <inheritdoc />
/// <remarks>Does nothing if user provides an <c>href</c> attribute.</remarks>
/// <exception cref="InvalidOperationException">
/// Thrown if <c>href</c> attribute is provided and <see cref="Action"/>, <see cref="Controller"/>,
/// <see cref="Fragment"/>, <see cref="Host"/>, <see cref="Protocol"/>, or <see cref="Route"/> are
/// non-<c>null</c> or if the user provided <c>asp-route-*</c> attributes. Also thrown if <see cref="Route"/>
/// and one or both of <see cref="Action"/> and <see cref="Controller"/> are non-<c>null</c>.
/// </exception>
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var routePrefixedAttributes = output.FindPrefixedAttributes(RouteAttributePrefix);
// If "href" is already set, it means the user is attempting to use a normal anchor.
if (output.Attributes.ContainsKey(Href))
{
if (Action != null ||
Controller != null ||
Route != null ||
Protocol != null ||
Host != null ||
Fragment != null ||
routePrefixedAttributes.Any())
{
// User specified an href and one of the bound attributes; can't determine the href attribute.
throw new InvalidOperationException(
Resources.FormatAnchorTagHelper_CannotOverrideHref(
"<a>",
ActionAttributeName,
ControllerAttributeName,
RouteAttributeName,
ProtocolAttributeName,
HostAttributeName,
FragmentAttributeName,
RouteAttributePrefix,
Href));
}
}
else
{
TagBuilder tagBuilder;
var routeValues = GetRouteValues(output, routePrefixedAttributes);
if (Route == null)
{
tagBuilder = Generator.GenerateActionLink(linkText: string.Empty,
actionName: Action,
controllerName: Controller,
protocol: Protocol,
hostname: Host,
fragment: Fragment,
routeValues: routeValues,
htmlAttributes: null);
}
else if (Action != null || Controller != null)
{
// Route and Action or Controller were specified. Can't determine the href attribute.
throw new InvalidOperationException(
Resources.FormatAnchorTagHelper_CannotDetermineHrefRouteActionOrControllerSpecified(
"<a>",
RouteAttributeName,
ActionAttributeName,
ControllerAttributeName,
Href));
}
else
{
tagBuilder = Generator.GenerateRouteLink(linkText: string.Empty,
routeName: Route,
protocol: Protocol,
hostName: Host,
fragment: Fragment,
routeValues: routeValues,
htmlAttributes: null);
}
if (tagBuilder != null)
{
output.MergeAttributes(tagBuilder);
}
}
}
示例3: FindPrefixedAttributes_ReturnsEmpty_AttributeListIfNoAttributesPrefixed
public void FindPrefixedAttributes_ReturnsEmpty_AttributeListIfNoAttributesPrefixed()
{
// Arrange
var tagHelperOutput = new TagHelperOutput(
"p",
attributes: new Dictionary<string, object>()
{
{ "routeHello", "World" },
{ "Routee-I", "Am" }
});
// Act
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
// Assert
Assert.Empty(attributes);
var attribute = Assert.Single(tagHelperOutput.Attributes, kvp => kvp.Key.Equals("routeHello"));
Assert.Equal(attribute.Value, "World");
attribute = Assert.Single(tagHelperOutput.Attributes, kvp => kvp.Key.Equals("Routee-I"));
Assert.Equal(attribute.Value, "Am");
}
示例4: RemoveRange_RemovesProvidedAttributes
public void RemoveRange_RemovesProvidedAttributes()
{
// Arrange
var tagHelperOutput = new TagHelperOutput(
"p",
attributes: new Dictionary<string, object>()
{
{ "route-Hello", "World" },
{ "Route-I", "Am" }
});
var expectedAttribute = new KeyValuePair<string, object>("type", "btn");
tagHelperOutput.Attributes.Add(expectedAttribute);
var attributes = tagHelperOutput.FindPrefixedAttributes("route-");
// Act
tagHelperOutput.RemoveRange(attributes);
// Assert
var attribute = Assert.Single(tagHelperOutput.Attributes);
Assert.Equal(expectedAttribute, attribute);
}
示例5: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
RouteValues = output.TrimPrefixedAttributes(RouteAttributePrefix);
AjaxValues = output.FindPrefixedAttributes(AjaxAttributePrefix);
ApplyActionAttributes();
ApplyPaginationAttributes(context);
ApplyIconTextAttributes();
output.TagName = null;
//if there are no rows then don't show
if (PageSize != 0 && Total != 0)
output.Content.SetContent(Create(PageIndex, Total, PageSize));
await base.ProcessAsync(context, output);
}