【发布时间】:2018-12-09 17:16:30
【问题描述】:
我有以下枚举
public class Blog {
public enum BlogType {
Article,
News
}
}
我想将其转换为下拉列表,但出现错误: 无法将类型“Blog.BlogType”隐式转换为“System.Collections.Generic.IEnumerable”
我的代码:
IList<SelectListItem> list = Enum.GetValues(typeof(Blog.BlogType))
.Cast<Blog.BlogType>()
.Select(x => new SelectListItem { Text = x.ToString(), Value = ((int)x).ToString() })
.ToList();
SelectList data = new SelectList(list, "Value", "Text");
我尝试了几种解决方案,但我遇到了同样的问题..
谢谢..
【问题讨论】:
标签: c# enums dropdown asp.net-core-2.1 razor-pages