Home > OS >  Populate SelectList with Font-Awesome Icons in ASP.NET MVC
Populate SelectList with Font-Awesome Icons in ASP.NET MVC

Time:10-19

I've populated List with font-awesome strings like:

    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>"
    };

And in View i have a dropdown:

<select asp-for="Icon" class="form-control" asp-items="ViewBag.Icons"></select>

and then when I display them in SelectList I get:

enter image description here

I would like to render them as html and display icons, not strings. Is it possible? Maybe with JS or jQuery?

CodePudding user response:

You cannot render <i> icon element in <option> element as asked this question:

  • Related