【发布时间】:2021-05-12 12:27:39
【问题描述】:
我正在尝试使用 enum 值填充下拉列表,但我遇到了问题。这是我的课
public class Project
{
...
public Currencies Money { get; set; }
public enum Currencies
{
[Display(Name = "Euro")]
Euro = 1,
[Display(Name = "USD")]
USD = 2
}
这是我的观点
@model Projects.Domain.Project
@{
ViewData["Title"] = "Create";
}
<br />
<p style="font-weight:bold;">Add new project</p>
<hr />
<div class="row">
<div class="col-md-4">
<form asp-action="Create">
<div class="form-group">
<select asp-for="Money" asp-items="@Html.GetEnumSelectList<Currencies>()"></select>
</div>
</form>
</div>
</div>
但我收到一条错误消息,提示 The type or namespace currencies could not be found. 如果我将 Currencies 替换为 Money,则结果相同。填充下拉列表的正确方法是什么?
【问题讨论】:
-
要么使用
Currencies的完全限定名称,要么为其命名空间添加 using 语句。