How to add razor page attribute inside i tag

Viewed 38
@Html.DropDownListFor(model => model.Template, Model.lstTemplate, "-Select-", new { @id = "Template", @class = "form-control", @style = "display:none;" })

I need to add <i class="fas fa-clock"></i> inside the dropdown

1 Answers

You can still do Model binding if you create the select manually

<select name="@Html.NameFor(m => m.Template)" id="@Html.IdFor(m => m.Template)" class="form-control">
    <option value="">-Select-</option>

    @foreach (var item in Model.lstTemplate)
    {
        <option value="@item" @(item == Model.lstTemplate ? "selected=selected" : "")>
            <i class="fas fa-clock"></i>
        </option>
    }
</select>
Related