I am writing an ASP.NET Blazor WASM program with an HTML select dropdown. It has a value
attribute that is linked to an enum variable type, and calls a custom method with the @onchange
directive.
Dropdown component
<select name="category" class="form-control selectpicker " value="@_searchCategory" @onchange="UpdateCategory">
@foreach (var item in Enum.GetValues(typeof(SearchCategory)))
{
<option value="@item">@item</option>
}
</select>
Search Variables
private SearchCategory _searchCategory = SearchCategory.Port;
private enum SearchCategory
{
Port,
Name,
Script,
Version
}
UpdateCategory method
UpdateCategory(ChangeEventArgs args) {
_searchCategory = args.Value; //error
PerformSearch();
...
}
How can I cast string
(args.Value) to Enum
(SearchCategory)?