TagBuilder InnerHtml in ASP.NET 5 MVC 6

后端 未结 6 978
难免孤独
难免孤独 2021-02-07 01:10

It seems to me that there are major breaking changes in TagBuilder as of beta7 with no mention about them in the announcements repo.

Specifically .ToString no longer ren

6条回答
  •  别那么骄傲
    2021-02-07 01:38

    Because TagBuilder now implements IHtmlContent, you should be able to use it directly, without doing .ToString().

    var li = new TagBuilder("li");
    li.AddCssClass("inactive");
    var span = new TagBuilder("span");
    span.SetInnerText(somestring);
    li.InnerHtml = span;
    

    The real problem with the current implementation in Beta 7 is that there is no easy way to append two child tag builder contents to a parent one. You can follow the discussion on GitHub.

    The current proposal is to make InnerHtml not assignable, but support Append instead. This is targeted to be implemented in Beta 8.

    The workaround in Beta 7 is to call parent.WriteTo with a StringWriter to convert it to a string.

提交回复
热议问题