How to emit unencoded html in the dropdown list in ASP.NET MVC
I want to populate a dropdown list with trademark and copyright characters but looks like th开发者_如何学Cey are always html encoded so what I get instead is their encoded form.
Thanks for your help.
When populating your SelectList, use HttpUtility.HtmlDecode on the text. Here's an example:
<%
var entities = new string[] { "©", "<">", "©" };
var selectListItems = entities.Select(e => new SelectListItem {
Text = HttpUtility.HtmlDecode(e), Value = "1"
});
%>
<%= Html.DropDownList("exampleDropDownList", selectListItems) %>
Or this way, if Model is SelectList
@Html.DropDownList("DropDownList", Model.Select(i => { i.Text = HttpUtility.HtmlDecode(i.Text); return i; }))
精彩评论