I would like to create a HtmlHelper function for a specific kind of dropdown that appears on many pages in my app. I'm basically just trying to add some decoration around the existing DropDownList function, but it's being encoded. Here's my extension method:
<Extension()> _
Public Function Year(ByVal HtmlHelper As System.Web.Mvc.HtmlHelper, ByVal name As String) As String
Return _
<label>
Year:
<%= HtmlHelper.DropDownList(name) %>
</label>.ToString
End Function
This returns the following:
<label>Year:<select id="year" name="year"><option value="2007">2007</option><option value="2008">2008</option><option selected="selected" value="2009">2009</option></select></label>
instead of what I want:
<label>Year:<select id="year" name="year"><option value="2007">2007</option><option value="2008">2008</option><option selected="selected" value="2009">2009</option></select></label>
In other words, the DropDownList is HTML encoded before the string is put inside the label. I could do it like this:
<Extension()> _
Public Function Year(ByVal HtmlHelper As System.Web.Mvc.HtmlHelper, ByVal name As String) As String
Return "<label>Year:" & HtmlHelper.DropDownList(name) & "</label>"
End Function
but I'd rather make use of VB's inline XML. How do I get the results of DropDownList to not be encoded?