首先是枚举对象的遍历
#region 类型列表框
typeitems = new List<SelectListItem>();
foreach (string i in Enum.GetNames(typeof(ServiceDocumentType)))
{
typeitems.Add(new SelectListItem { Text = ((ServiceDocumentType)
Enum.Parse(typeof(ServiceDocumentType), i)).GetDescription(),
Value = ((int)((ServiceDocumentType)
Enum.Parse(typeof(ServiceDocumentType), i))).ToString() });
}
#endregion
ServiceDocumentCreateModel model = new ServiceDocumentCreateModel
{
ProductID = entity.ProductID,
Content = entity.Content,
DownloadUrl = entity.DownloadUrl,
ImageUrl = entity.ImageUrl,
Level = entity.Level,
LinkUrl = entity.LinkUrl,
Title = entity.Title,
Type = new SelectList(typeitems, "Value", "Text", (int)entity.Type),
Status = new SelectList(statusItems, "Value", "Text", (int)entity.Status),
};
其中Type和Status都是SelectList类型,这样方便前台Model在VIEW中的展示。
前台中展示就一句搞定:
<%=Html.DropDownList("Type",Model.Type)%>