我们说我有这样的枚举:
public enum ContactPhoneType
{
[Display(Name = "")]
None = 0,
[Display(Name = "Home Phone")]
HomePhone = 1,
[Display(Name = "Cell/Mobile Phone")]
CellMobile = 2,
[Display(Name = "Work Phone")]
Work = 3,
[Display(Name = "Family Member")]
FamilyMember = 4,
[Display(Name = "Fax Number")]
Fax = 5,
[Display(Name = "Other")]
Other = 6,
}
我想只显示列表中的前6个。我该如何隐藏最后一个?
为了显示所有项目,我使用了以下代码:
<div class="form-group">
<label class="col-sm-4 control-label" asp-for="PhoneNumberType"></label>
<div class="col-sm-6">
<select asp-for="PhoneNumberType" asp-items="Html.GetEnumSelectList<ContactPhoneType>()" class="form-control"></select>
</div>
</div>
答案 0 :(得分:4)
如果该方法返回一个继承自IEnumerable<T>
的集合,您可以使用Take()
方法按以下方式选择其前N个元素:
asp-items="Html.GetEnumSelectList<ContactPhoneType>().Take(6)"
希望它有所帮助!