How do I display the DisplayAttribute.Description attribute value?

前端 未结 12 1927
醉梦人生
醉梦人生 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条回答
  •  天命终不由人
    2020-11-27 03:56

    Using the technique from this article about how to Display visual hints for the fields in your form, you can access the value via the following:

    @Html.TextBoxFor( 
            model => model.Email , 
            new { title = ModelMetadata.FromLambdaExpression( 
                model => model.Email , ViewData ).Description } )  
    

提交回复
热议问题