Unable to combine tags using TagBuilder

asp.net-mvc-4, c#, html-helper

Solution

Try like this:

var label = new TagBuilder("label");
label.Attributes.Add("id", "required" + id);
//I get the id earlier fyi - not pertinent fyi for this question )

// Create the Span
var span = new TagBuilder("span");
span.AddCssClass("requiredInidicator");
span.SetInnerText("* ");

//Now combine the span's content with the label tag
label.InnerHtml = span.ToString(TagRenderMode.Normal) + htmlHelper.Encode(labelText);
return MvcHtmlString.Create(label.ToString(TagRenderMode.Normal));

Problem

I'm trying to build a combination tag: First tag: `<span class="requiredInidicator">* </span>` Second tag: `<label>SomeText</label>` (Attributes snipped for brevity) I would like to combine these to return an MVCHtmlString but the following code ignores the span completely. Could someone point out what I am doing wrong Here is my code: ``` // Create the Label var tagBuilder = new TagBuilder("label"); tagBuilder.Attributes.Add("id", "required" + id); //I get the id earlier fyi - not pertinent fyi for this question ) // Create the Span var required = new TagBuilder("span"); required.AddCssClass("requiredInidicator"); required.SetInnerText("* "); //Now combine the span's content with the label tag tagBuilder.InnerHtml += required.ToString(TagRenderMode.Normal); tagBuilder.SetInnerText(labelText); var tag = MvcHtmlString.Create(tagBuilder.ToString(TagRenderMode.Normal)); return tag; ``` When the tag is created, the span is ignored completely. When I inspect the tag during debug, it doesn't care about the required that I appended via `.InnerHtml+=` Is there something obvious I am doing wrong?

Original source