【发布时间】:2020-02-08 03:55:22
【问题描述】:
如果我有以下标签助手:
using Microsoft.AspNetCore.Razor.TagHelpers;
namespace CustomTagHelper.TagHelpers
{
[HtmlTargetElement("my-first-tag-helper")]
public class MyCustomTagHelper : TagHelper
{
public string Id { get; set; }
public string Type { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.SuppressOutput();
output.Content.Clear();
output.Content.SetHtmlContent($"<input id={Id} type={Type} />");
}
}
}
在视图中我传递了这个:
<my-first-tag-helper id="my-input" type="text" placeholder="type anything you want" autocomplete="off" disabled="disabled" />
我希望能够访问任何其他添加到该标记但不是标记助手属性的属性,以便我可以将它们添加到输出中。在此示例中,它们将是占位符、自动完成和禁用。
在前面的例子中,结果标签应该是:
<input id="my-input" type="text" placeholder="type anything you want" autocomplete="off" disabled="disabled" />
那么,我如何访问那些不是属性的属性?
【问题讨论】:
标签: c# asp.net model-view-controller tag-helpers asp.net-core-tag-helpers