0

我有这个方法:

 while (created < 2)
        {
      var tb = new TagBuilder("input");
            tb.MergeAttribute("id", model.QuestionId);
            tb.MergeAttribute("name", model.QuestionId);
            tb.MergeAttribute("type", "radio");
            if (model.Disabled == true)
            {
                tb.MergeAttribute("Disabled", model.Disabled.ToString());
            }
            tb.MergeAttributes(GetHtmlAttributes(model.HtmlAttributes));
            tb.AddCssClass("form-field");
            var innerText = created % 2 == 0 ? "Kvinna" : "Man";
            tb.MergeAttribute("value", innerText);
            sb.Append(tb.ToString(TagRenderMode.SelfClosing));
            var spanBuilder = new TagBuilder("span");
            spanBuilder.SetInnerText(innerText);

   This code ---> var spanBuilders = new TagBuilder("span");
            spanBuilders.MergeAttribute("id", model.QuestionId + "radio");
            spanBuilders.MergeAttribute(spanBuilder.ToString((TagRenderMode.Normal)));<--- 

            sb.Append(spanBuilder.ToString(TagRenderMode.Normal));
}

我想要做的是以某种方式合并 span-tag spanbuilder 并将其放入另一个标签中。while-loop 会通过两次,因此它将创建 spanbuilder 的两个跨度标签,我希望它们的展位位于另一个跨度标签内。有没有好的方法来做到这一点?

4

1 回答 1

0

您应该为 Span 标签创建一个 DocFragment,然后将其附加到父级。我建议您使用 XMLDocument 或 XDocument 来执行此操作。参见X 文档链接

于 2013-07-26T09:49:26.787 回答