开发者

How to render a self closing tag using TagBuilder?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜