基于这篇文章:How do you create a dropdownlist from an enum in ASP.NET MVC?
我想做完全相同的事情,除了使用枚举中的 AttributeDescription 字段,例如:
[DescriptionAttribute("1 Star")] OneStar = 1,
[DescriptionAttribute("2 Stars")] TwoStar = 2,
[DescriptionAttribute("3 Stars")] ThreeStar = 3,
[DescriptionAttribute("4 Stars")] FourStar = 4
Run Code Online (Sandbox Code Playgroud)
前面的链接中给出的解决方案将在下拉列表的文本字段中显示“OneStar”,而我希望看到“1 Star”。我看过一些与此相关的帖子,但他们的解决方案非常冗长。