以下代码:
var canonical = new TagBuilder("link");
canonical.MergeAttribute("rel", "canonical");
canonical.MergeAttribute("href", url);
return new MvcHtmlString(canonical.ToString());
创建标记:
<link href="http://local.domain.com/" rel="canonical"></link>
是否可以渲染
<link href="http://local.domain.com/" rel="canonical"/>
相反,使用TagBuilder?
答案 0 :(得分:76)
你试过了吗?
canonical.ToString(TagRenderMode.SelfClosing);
答案 1 :(得分:1)
你也可以试试。
TagBuilder tagBuilder = new TagBuilder("link");
tagBuilder.TagRenderMode = TagRenderMode.SelfClosing;