在選擇串列的視圖中,它將 HTML 標記顯示為文本
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
});
}
這就是視圖
<select class="js-example-basic-single col-lg-6 mb-2" asp-for="Color.Id" asp-items="selectListColor" multiple></select>
uj5u.com熱心網友回復:
如果要使用 colorList 設定選項:
@foreach (var productColorDto in colorList)
{
if (config.Color.Id == productColorDto.Id)
{
<option value=@productColorDto.Id.ToString() selected>@productColorDto.Name-<span class='item fa fa-circle' style='color: @productColorDto.HexValue'></span></option>
}
else
{
<option value=@productColorDto.Id.ToString()>@productColorDto.Name-<span class='item fa fa-circle' style='color: @productColorDto.HexValue'></span></option>
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/424695.html
標籤:网 asp.net-mvc asp.net 核心
