public class TradeModel { [Display(Name = "编号")] public int Id { get; set; } [Display(Name = "物品名称")] [StringLength(200, MinimumLength = 1)] [Required(ErrorMessage = "此项不能为空")] public string Tradename { get; set; } [Display(Name = "物品数量")] public Nullable<double> Quantity { get; set; } [Display(Name = "物品单位")] public string Quantityunits { get; set; }
[Display(Name = "价格")] [DisplayFormat(DataFormatString = "{0:F}")] public Nullable<double> Prices { get; set; } #region 扩展属性 不映射表字段 /// <summary> /// 物品单位枚举描述值获取 /// </summary> [NotMapped] public string QuantityunitsDescription { get { return Utils.EnumHelper.GetDescription<EnumModel.EnumQuantityunits>(Quantityunits); } set { Quantityunits = value; } }#endregion }
@foreach (var item in Model.Trades) { //显示对应枚举值 @Html.DisplayFor(modelItem => item.QuantityunitsDescription) } <label asp-for="Tradename" class="control-label"></label> <input asp-for="Tradename" class="form-control" /> <span asp-validation-for="Tradename" class="text-danger"></span>