我想填充一个带有商标和版权字符的下拉列表,但看起来它们总是被html编码,所以我得到的是它们的编码形式。
感谢您的帮助。
答案 0 :(得分:5)
填充SelectList时,请在文本上使用HttpUtility.HtmlDecode。这是一个例子:
<%
var entities = new string[] { "©", "<">", "©" };
var selectListItems = entities.Select(e => new SelectListItem {
Text = HttpUtility.HtmlDecode(e), Value = "1"
});
%>
<%= Html.DropDownList("exampleDropDownList", selectListItems) %>
答案 1 :(得分:0)
或者这样,如果Model是SelectList
@Html.DropDownList("DropDownList", Model.Select(i => { i.Text = HttpUtility.HtmlDecode(i.Text); return i; }))