本文整理汇总了C#中Microsoft.AspNet.Razor.Runtime.TagHelpers.TagHelperOutput类的典型用法代码示例。如果您正苦于以下问题:C# TagHelperOutput类的具体用法?C# TagHelperOutput怎么用?C# TagHelperOutput使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TagHelperOutput类属于Microsoft.AspNet.Razor.Runtime.TagHelpers命名空间,在下文中一共展示了TagHelperOutput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (!string.IsNullOrWhiteSpace(Value))
{
output.Content.SetContent(Value);
}
}
示例2: 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));
}
示例3: Process
public override void Process(TagHelperContext context, TagHelperOutput output) {
if (Date == null) throw new ArgumentNullException("Missing date argument on DateDest tag");
if (Type == DateDestType.NotSet) throw new ArgumentNullException("Missing date type");
// Build outer row
output.TagName = "div";
output.Attributes["class"] = "timeRow";
output.TagMode = TagMode.StartTagAndEndTag;
AddTopLabels(output);
output.Content.AppendEncoded("<div class=\"row\">");
AddDatePart(output, "month", 3);
AddDatePart(output, "day", 1);
AddDatePart(output, "year", 3);
AddDatePart(output, "pm", 1);
AddDatePart(output, "hour", 2);
AddDatePart(output, "min", 2);
output.Content.AppendEncoded("</div>");
AddDateLabel(output);
}
示例4: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
var surroundingTagName = Surround.ToLowerInvariant();
output.PreElement.SetContent($"<{surroundingTagName}>");
output.PostElement.SetContent($"</{surroundingTagName}>");
}
示例5: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "ul";
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 name in actionNames)
{
if (!string.Equals(name, Exclude, StringComparison.OrdinalIgnoreCase))
{
var displayName =
string.Equals(name, "Index", StringComparison.OrdinalIgnoreCase) ? controllerName : name;
output.PostContent.Append($"<li><a href='{UrlHelper.Action(name, controllerName)}'>{displayName}</a></li>");
}
}
}
示例6: 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();
}
示例7: 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);
}
示例8: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
if (10%new Random().Next(2,11) != 0) return; // Only implements the mirror 10% of the time
output.PostElement.SetContentEncoded([email protected]"
<script>
var rotate = 0;
function rotateBody() {{
if (rotate>359) {{ rotate=0; }}
var rotation = 'rotate('+ (rotate += 0.1) +'deg)'
var el = document.getElementsByTagName('body')[0];
el.style = el.style || {{}};
el.style.transform = el.style.transform || '';
arr = el.style.transform.split(' ');
var registered = false;
for(var i=0;i<arr.length;i++)
{{
if(arr[i].slice(0, 6) == 'rotate') {{
arr[i] = rotation;
registered=true;
}}
}}
if (!registered) {{ arr.push(rotation); }}
el.style.transform = arr.join(' ');
}}
setInterval(rotateBody, 300);
</script>");
}
示例9: 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);
}
示例10: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = null;
output.Content.AppendEncoded("<b>");
output.Content.Append(text);
output.Content.AppendEncoded("</b>");
}
示例11: 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>");
}
示例12: 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);
// }
//}
}
示例13: 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);
}
示例14: Process
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.PostContent
.AppendEncoded("<footer>")
.Append((string)ViewContext.ViewData["footer"])
.AppendEncoded("</footer>");
}
示例15: 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)));
}