【发布时间】:2021-12-03 17:07:13
【问题描述】:
我已经用字体很棒的字符串填充了列表,例如:
private static readonly List<string> Icons = new(){
"<i class=\"fas fa-users\"></i>",
"<i class=\"fas fa-user-tag\"></i>",
"<i class=\"fas fa-sitemap\"></i>",
"<i class=\"fas fa-cubes\"></i>",
"<i class=\"fas fa-shield-alt\"></i>"
};
在视图中我有一个下拉列表:
<select asp-for="Icon" class="form-control" asp-items="ViewBag.Icons"></select>
然后当我在 SelectList 中显示它们时,我得到:
我想将它们呈现为 html 并显示图标,而不是字符串。可能吗?也许用 JS 或 jQuery?
【问题讨论】:
-
我认为没有 hacks 是不可能的,afaik 选项元素不支持其中的 html,因此您必须创建一个行为类似于 select 的自定义元素
-
是否有可能使用 jQuery 或仅使用 JS?
-
我认为这是可能的,看看这里w3schools.com/howto/howto_custom_select.asp
-
如果我没记错的话,Tag Helper is for ASP.NET Core MVC。您可以将问题标签更改为
.net-core、asp.net-core-mvc、asp.net-core相关标签。
标签: c# asp.net .net asp.net-mvc razor