本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperContext类的典型用法代码示例。如果您正苦于以下问题:C# TagHelperContext类的具体用法?C# TagHelperContext怎么用?C# TagHelperContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TagHelperContext类属于Microsoft.AspNet.Razor.Runtime.TagHelpers命名空间,在下文中一共展示了TagHelperContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetContent
private async Task<string> GetContent(TagHelperContext context)
{
if (Content == null)
return (await context.GetChildContentAsync()).GetContent();
return Content.Model?.ToString();
}
示例2: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!Condition)
{
output.SuppressOutput();
}
}
示例3: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
if (!string.IsNullOrWhiteSpace(ModelName) && ModelData != null)
{
modelContext.Initialize(ModelData);
var script = new TagBuilder("script");
script.Attributes.Add("model", ModelName);
script.Attributes.Add("type", "application/json");
if (ModelPersistent)
{
script.Attributes.Add("persistent", "");
}
script.InnerHtml = new StringHtmlContent(jsonHelper.Serialize(ModelData).ToString());
output.Attributes.Add("model", ModelName);
using (var writer = new StringWriter())
{
script.WriteTo(writer, new HtmlEncoder());
output.PreContent.SetContent(writer.ToString());
}
}
else if (!string.IsNullOrWhiteSpace(Scope))
{
output.Attributes.Add("scope", Scope);
modelContext.Scope(Scope);
}
output.Attributes.Add("name", Name);
await base.ProcessAsync(context, output);
}
示例4: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
(HtmlHelper as ICanHasViewContext)?.Contextualize(ViewContext);
var content = await context.GetChildContentAsync();
output.Content.SetContent(HtmlHelper.Hidden(Name, content.GetContent(HtmlEncoder)));
}
示例5: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await context.GetChildContentAsync();
var content = childContent.GetContent();
var template =
[email protected]"<div class='modal-dialog' role='document'>
<div class='modal-content'>
<div class='modal-header'>
<button type = 'button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>×</span></button>
<h4 class='modal-title' id='{context.UniqueId}Label'>{Title}</h4>
</div>
{content}
</div>
</div>";
output.TagName = "div";
output.Attributes["role"] = "dialog";
output.Attributes["id"] = Id;
output.Attributes["aria-labelledby"] = $"{context.UniqueId}Label";
output.Attributes["tabindex"] = "-1";
var classNames = "modal fade";
if (output.Attributes.ContainsName("class"))
{
classNames = string.Format("{0} {1}", output.Attributes["class"].Value, classNames);
}
output.Attributes["class"] = classNames;
output.Content.SetContent(template);
}
示例6: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = null;
output.Content.AppendEncoded("<b>");
output.Content.Append(text);
output.Content.AppendEncoded("</b>");
}
示例7: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var contacts = new ContactRepository();
var contact = await contacts.GetAsync(Email);
if (contact == null)
{
output.TagName = null;
return;
}
output.TagName = "div";
output.PreContent.SetContentEncoded("<form>");
var hidden = CreateInputElement("hidden", contact.Id.ToString());
var textBox = CreateInputElement("text", "");
var submit = CreateInputElement("submit", "Send Message");
output.Content.Append(hidden);
output.Content.Append(textBox);
output.Content.Append(submit);
output.PostContent.SetContentEncoded("</form>");
}
示例8: Process
//[HtmlAttributeName("DisplaySteps")]
//public bool DisplaySteps { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
// [initial-board] -> [solved-board]
// seqences of boards
if(MoveResult == null) {
output.SuppressOutput();
return;
}
output.TagName = "span";
AddBoardToOutput(MoveResult.OriginalBoard.Board, output);
output.Content.AppendEncoded(Environment.NewLine);
output.Content.AppendEncoded(@" ");
AddBoardToOutput(MoveResult.CurrentBoard.Board, output);
//if (DisplaySteps) {
// output.Content.AppendEncoded(Environment.NewLine);
// output.Content.AppendEncoded(@"<br/>");
// output.Content.AppendEncoded(@"<div style=""height: 10px;""> </div>");
// foreach (var move in MoveResult.MovesPlayed) {
// AddBoardToOutput(move.Board, output);
// output.Content.AppendEncoded(@" ");
// output.Content.AppendEncoded(Environment.NewLine);
// }
//}
}
示例9: CopyHtmlAttribute_DoesNotOverrideAttributes
public void CopyHtmlAttribute_DoesNotOverrideAttributes()
{
// Arrange
var attributeName = "hello";
var tagHelperOutput = new TagHelperOutput(
"p",
attributes: new Dictionary<string, object>()
{
{ attributeName, "world2" }
});
var expectedAttribute = new KeyValuePair<string, object>(attributeName, "world2");
var tagHelperContext = new TagHelperContext(
allAttributes: new Dictionary<string, object>(StringComparer.Ordinal)
{
{ attributeName, "world" }
},
items: new Dictionary<object, object>(),
uniqueId: "test",
getChildContentAsync: () =>
{
var tagHelperContent = new DefaultTagHelperContent();
tagHelperContent.Append("Something Else");
return Task.FromResult<TagHelperContent>(tagHelperContent);
});
// Act
tagHelperOutput.CopyHtmlAttribute(attributeName, tagHelperContext);
// Assert
var attribute = Assert.Single(tagHelperOutput.Attributes);
Assert.Equal(expectedAttribute, attribute);
}
示例10: ProcessAsync
public override async Task ProcessAsync(TagHelperContext context, TagHelperOutput output)
{
var childContent = await context.GetChildContentAsync();
var modalContext = (ModalContext)context.Items[typeof(ModalTagHelper)];
modalContext.Body = childContent;
output.SuppressOutput();
}
示例11: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!string.IsNullOrWhiteSpace(Value))
{
output.Content.SetContent(Value);
}
}
示例12: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = null;
ConditionalCommentType type = CommentType;
string ifCommentStartPart;
string ifCommentEndPart;
switch (type)
{
case ConditionalCommentType.Hidden:
ifCommentStartPart = "<!--[if ";
ifCommentEndPart = "]>";
break;
case ConditionalCommentType.RevealedValidating:
ifCommentStartPart = "<!--[if ";
ifCommentEndPart = "]><!-->";
break;
case ConditionalCommentType.RevealedValidatingSimplified:
ifCommentStartPart = "<!--[if ";
ifCommentEndPart = "]>-->";
break;
case ConditionalCommentType.Revealed:
ifCommentStartPart = "<![if ";
ifCommentEndPart = "]>";
break;
default:
throw new NotSupportedException();
}
TagHelperContent preContent = output.PreContent;
preContent.Append(ifCommentStartPart);
preContent.Append(Expression);
preContent.Append(ifCommentEndPart);
string endIfComment;
switch (type)
{
case ConditionalCommentType.Hidden:
endIfComment = "<![endif]-->";
break;
case ConditionalCommentType.RevealedValidating:
case ConditionalCommentType.RevealedValidatingSimplified:
endIfComment = "<!--<![endif]-->";
break;
case ConditionalCommentType.Revealed:
endIfComment = "<![endif]>";
break;
default:
throw new NotSupportedException();
}
output.PostContent.Append(endIfComment);
}
示例13: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "ul";
output.TagMode = TagMode.StartTagAndEndTag;
var actionNames = ControllerType.GetTypeInfo().DeclaredMethods
.Where(methodInfo => methodInfo.IsPublic)
.Select(methodInfo => methodInfo.Name);
var controllerName = ControllerType.Name;
if (controllerName.EndsWith("Controller", StringComparison.OrdinalIgnoreCase))
{
controllerName = controllerName.Substring(0, controllerName.Length - "Controller".Length);
}
foreach (var action in actionNames)
{
if (!string.Equals(action, Exclude, StringComparison.OrdinalIgnoreCase))
{
var displayName = action;
if (string.Equals(action, "Index", StringComparison.OrdinalIgnoreCase))
{
displayName = controllerName;
}
var liElement = new HtmlString($"<li><a href='{_urlHelper.Action(action, controllerName)}'>{displayName}</a></li>");
output.Content.Append(liElement);
}
}
}
示例14: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (Type != null && Status != null)
throw new ArgumentException($"'{nameof(Type)}' and '{nameof(Status)}' attributes cannot be used together.");
output.TagName = null;
output.Content.SetContent(ShieldGenerator.GenerateShieldMarkup(Subject, Type, Status, Color, Style, Image));
}
示例15: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.PostContent
.AppendEncoded("<footer>")
.Append((string)ViewContext.ViewData["footer"])
.AppendEncoded("</footer>");
}