开发者

How to render a self closing tag using TagBuilder?

开发者 https://www.devze.com 2023-02-07 05:44 出处:网络
The following code: var canonical = new TagBuilder(\"link\"); canonical.MergeAttribute(\"rel\", \"canonical\");

The following code:

var canonical = new TagBuilder("link");
canonical.MergeAttribute("rel", "canonical");
canonical.MergeAttribute("href", url);
return new MvcHtmlString(canonical.ToString());

Creates a tag:

<link href="http://local.domain.com/" rel="canonical"></link>

Is it possible to render

<link h开发者_开发问答ref="http://local.domain.com/" rel="canonical"/>

instead, using TagBuilder?


Have you tried:

canonical.ToString(TagRenderMode.SelfClosing);


You can also try.

TagBuilder  tagBuilder = new TagBuilder("link");
tagBuilder.TagRenderMode = TagRenderMode.SelfClosing;
0

精彩评论

暂无评论...
验证码 换一张
取 消