Joh*_*ika 4 asp.net-core-mvc tag-helpers asp.net-core asp.net-core-2.0 asp.net-core-tag-helpers
使用 ASP.Net Core 的 Tag Helpers,有没有办法在根级别将 1 个标签转换为 2 个标签?我知道您可以使用 完全删除标签TagHelperOutput.TagName == null,但我想知道如何做相反的事情来输出多个标签。
例如,从:
<canonical href="/testing" />
Run Code Online (Sandbox Code Playgroud)
到:
<link rel="canonical" href="http://www.examples.com/widgets" />
<link rel="next" href="http://www.examples.com/widgets?page=2" />
Run Code Online (Sandbox Code Playgroud)
这是一个示例标签助手,它输出一个标签,但不是两个:
[HtmlTargetElement("canonical")]
public class CanonicalLinkTagHelper : TagHelper
{
public string Href { get; set; }
public override void Process(TagHelperContext context, TagHelperOutput output)
{
output.TagName = "link";
output.Attributes.SetAttribute("rel", "canonical");
output.Attributes.SetAttribute(new TagHelperAttribute("href", new HtmlString(Href)));
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
657 次 |
| 最近记录: |