Just getting back into coding after a long hiatus... I'm trying to display a list from an enum using Html.GetEnumSelectList<>, however Visual Studio 2019 does not seem to recognize (no intellisense) and the code is not working.
@using AspNetCoreVideo.Models
@model AspNetCoreVideo.Entities.Video
@addTagHelper *, Microsoft.aspnetcore.mvc.taghelpers
<h2>Create Vidio</h2>
<form asp-action="Create" method="post">
<table>
<tr>
<td><label asp-for="Title"></label></td>
<td><input asp-for="Title" /></td>
</tr>
<tr>
<td><label asp-for="Genre"></label></td>
< td><select asp-for="Genre" asp-items="Html.GetEnumSelectList<Genres>()"></select></td>
</tr>
</table>
<input type="submit" value="Create" />
</form>
Expecting a list of "Genres" to display, however, nothing is in the list.
I also had the similar issue, the select was showing nothing. Later I found that it was because of the usage of the select tag. If you use it as a single element like this <select /> it isn't gonna work. You have to use it as <select></select>
Hope this would help someone.
Issue Resolved. Apparently, @addTagHelper directive is case sensitive. I changed "@addTagHelper *, Microsoft.aspnetcore.mvc.taghelpers" to "@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers" and now the tag helpers work fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With