Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to emit unencoded html in the dropdown list in ASP.NET MVC

Tags:

asp.net-mvc

I want to populate a dropdown list with trademark and copyright characters but looks like they are always html encoded so what I get instead is their encoded form.

Thanks for your help.

like image 880
Imran Rashid Avatar asked Feb 28 '11 20:02

Imran Rashid


1 Answers

When populating your SelectList, use HttpUtility.HtmlDecode on the text. Here's an example:

<%
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) %>
like image 188
Shashi Penumarthy Avatar answered Oct 23 '22 04:10

Shashi Penumarthy