So I am creating a HtmlHelper extension method and I have run into a problem when using TagBuilder.SetInnerText(). The helper outputs an option tag. Here is the source of the helper:
public static string Option(this HtmlHelper helper, string value, string text, object htmlAttributes) {
TagBuilder tagBuilder = new TagBuilder("option");
tagBuilder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
tagBuilder.MergeAttribute("value", value);
tagBuilder.SetInnerText(text);
return tagBuilder.ToString(TagRenderMode.SelfClosing);
}
In my view I call
<%= Html.Option("value", "text", new { }) %>
but the inner text of the tag does not get set and I am left with
<option value="value"> </option>
Any ideas on why the SetInnerText() is not setting the text correctly?
Thanks.