In my cshtml view I have this pre-made (scaffold) code that I changed a little to be able to put a list of enums down there instead of a textbox:
<div class="form-group">
<label asp-for="Color" class="control-label"></label>
<select asp-for="Color" asp-items="Model.Colors" class="form-control"></select>
<span asp-validation-for="Color" class="text-danger"></span>
</div>
Error occurs at Model.Colors.
And in my model I tried doing: Colors.Add(new List<SelectListItem>()); as told in Cannot implicitly convert type 'System.Web.Mvc.SelectList' to 'System.Collections.Generic.ICollection<System.Web.Mvc.SelectList>', but than I would get a different error; Cannot implicitly convert 'System.Collections.Generic.List' to 'System.Web.Mvc.SelectListItem'.
Even though Colors is a List<SelectListItem>.
But before that I had this in the ViewModel:
public EnumsDTO.Color Color { get; set; }
public List<SelectListItem> Colors { get; set; }
public void AddColorViewModel()
{
Colors = new List<SelectListItem>();
foreach (Color c in (Color[])Enum.GetValues(typeof(Color)))
{
Colors.Add(new SelectListItem
{
Value = ((int)c).ToString(),
Text = c.ToString()
});
}
}
I was trying to follow this tutorial: https://www.youtube.com/watch?v=MPJ9PPCWxoI
usingat the top of the fileasp-items = Model.etcusingshould I have?