How to display the "Display(Name="My Name") data annotation with a form field?

1 Answer 32 Views
Form
Jstemper
Top achievements
Rank 1
Iron
Jstemper asked on 06 Jul 2021, 01:59 PM
I use data annotations heavily in my view models. I understand that if I let the Telerik form tag I can get the labels to generate and display from my data annotations but I am not auto generating my forms.   How do I make use of the Data Annotations with hand crafted forms?

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 06 Jul 2021, 05:54 PM

Hello,

The solution is to use a bit of reflection to extract the model metadata that you want to use, you can find similar examples here: https://stackoverflow.com/questions/7027613/how-to-retrieve-data-annotations-from-code-programmatically - you can easily make that into an extension method to call from the UI rendering.

 

Regards,
Marin Bratanov
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Tags
Form
Asked by
Jstemper
Top achievements
Rank 1
Iron
Answers by
Marin Bratanov
Telerik team
Share this question
or