asp.net-corerazorselectlistasp.net-core-tag-helpers

formselect url encoding of select list causing issues


I am creating a select list as follows:

<formselect id="CountryDropdown" class="form-select form-control form-control-sm"
            asp-for="Country"
            asp-items="@(new SelectList(@ViewBag.Countries,"TextColumn","TextColumn"))"></formselect>

@ViewBag.Countries contains the item

COTE D'IVOIRE

The formselect tag helper converts this to:

<option value="COTE D&#x27;IVOIRE">COTE D&#x27;IVOIRE</option>

How do I get the entry in the select list to be

<option value="COTE D'IVOIRE">COTE D'IVOIRE</option>

Solution

  • I solved this by editing the code that loaded ViewBag.Countries. The below code is used to eliminate D&#x27

    foreach (LookupListItem l in items)
        l.TextColumn = l.TextColumn.Replace("'", "&apos;");