如何在ASP.NET MVC的下拉列表中发出未编码的html

Imr*_*hid 5 asp.net-mvc

我想填充一个带有商标和版权字符的下拉列表,但看起来它们总是被html编码,所以我得到的是它们的编码形式.

谢谢你的帮助.

Sha*_*thy 5

填充SelectList时,请在文本上使用HttpUtility.HtmlDecode.这是一个例子:

<%
var entities = new string[] { "&copy;", "&lt;&quot;&gt;", "&#169;" };
var selectListItems = entities.Select(e => new SelectListItem { 
                                    Text = HttpUtility.HtmlDecode(e), Value = "1" 
                               });
%>

<%= Html.DropDownList("exampleDropDownList", selectListItems) %>
Run Code Online (Sandbox Code Playgroud)