【发布时间】:2012-10-22 07:40:27
【问题描述】:
这是我的枚举
public class Woodshape
{
public enum eWoodShape
{
Round = 10,
Oval = 20,
Plain = 30
}
}
现在我想将它作为下拉列表添加到我的控制器中
public ActionResult Create()
{
List<string> li = new List<string>();
FieldInfo[] myEnumFields = typeof(Woodshape.eWoodShape).GetFields();
foreach (FieldInfo myField in myEnumFields)
{
if (!myField.IsSpecialName && myField.Name.ToLower() != "notset")
{
int myValue = (int)myField.GetValue(0);
li.Add(myField.Name);
}
}
ViewBag.ddlEnumshape = new SelectList(myEnumFields, "myValue", "Name");
return View();
}
在我看来,将其绑定为..
<div>
@Html.DropDownList("ddlEnumshape", "-Select shape-")
/<div>
但是,它显示错误
System.Reflection.RtFieldInfo' does not contain a property with the name 'myValue'.
谁能帮帮我
【问题讨论】:
标签: c# asp.net-mvc-3 enums