3 回答

TA贡献1820条经验 获得超9个赞
如果您想要真正简单的东西,那么还有另一种方法,这取决于您将状态存储在数据库中的方式。
如果您拥有这样的实体:
public class Address
{
//other address fields
//this is what the state gets stored as in the db
public byte StateCode { get; set; }
//this maps our db field to an enum
public States State
{
get
{
return (States)StateCode;
}
set
{
StateCode = (byte)value;
}
}
}
然后生成下拉列表将像这样简单:
@Html.DropDownListFor(x => x.StateCode,
from State state in Enum.GetValues(typeof(States))
select new SelectListItem() { Text = state.ToString(), Value = ((int)state).ToString() }
);
LINQ不漂亮吗?
- 3 回答
- 0 关注
- 491 浏览
添加回答
举报