0
这是我的枚举获取下拉列表枚举在asp.net MVC3
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'.
谁能帮我
感谢您的代码,它的工作 – user1469330
@ ser1469330,请注意,响应来了 – Mediator