How to emit unencoded html drop-down in ASP.NET MVC

I want to populate the drop-down list with trademark and copyright symbols, but it looks like they are always html encoded, so instead I get their encoded form.

Thank you for your help.

+4
source share
2 answers

When populating SelectList, use the text HttpUtility.HtmlDexode. Here is 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) %> 
+4
source

Or in this way, if Model is a SelectList

  @Html.DropDownList("DropDownList", Model.Select(i => { i.Text = HttpUtility.HtmlDecode(i.Text); return i; })) 
0
source

Source: https://habr.com/ru/post/1341696/


All Articles