How do I display the DisplayAttribute.Description attribute value?

前端 未结 12 1857
醉梦人生
醉梦人生 2020-11-27 03:26

I have a model class, with a property like this:

[Display(Name = \"Phone\", Description=\"Hello World!\")]
public string Phone1 { get; set; }
12条回答
  •  -上瘾入骨i
    2020-11-27 04:04

    @ViewData.ModelMetadata.Properties
       .Where(m => m.PropertyName == "Phone1").FirstOrDefault().Description
    

    So, if you were using bootstrap, something like

    @Html.LabelFor(m => m.Organization.Phone1) @Html.EditorFor(m => m.Organization.Phone1)

    @ViewData.ModelMetadata.Properties .Where(m => m.PropertyName == "DayCount").FirstOrDefault().Description

提交回复
热议问题