in the view of the select list, it shows HTML tags as text
foreach (var productColorDto in colorList)
{
colorSelectList.Add(new SelectListItem
{
Value = productColorDto.Id.ToString(),
Text = productColorDto.Name " - "
$"<span class='item fa fa-circle' style='color: {productColorDto.HexValue}'></span>",
Selected = config.Color.Id == productColorDto.Id
});
}
and this is the view
<select asp-for="Color.Id" asp-items="selectListColor" multiple></select>
CodePudding user response:
If you want to set options with colorList:
@foreach (var productColorDto in colorList)
{
if (config.Color.Id == productColorDto.Id)
{
<option [email protected]() selected>@productColorDto.Name-<span class='item fa fa-circle' style='color: @productColorDto.HexValue'></span></option>
}
else
{
<option [email protected]()>@productColorDto.Name-<span class='item fa fa-circle' style='color: @productColorDto.HexValue'></span></option>
}
}