I have come across a scenerio that to customize DataAnnotations in Dynamic Data Web Application. This is the scenerio:
[Display(Name="DispName")]
public string DName{get;set;}
Instead of hardcoding Name="DispName" for Display DataAnnotation, I want to fetch some value from DataBase and fit int the Name attribute. like:
[Display(Name=SomeValueFromDB)]
public string DName{get;set;}
Is there any way to show the Name attribute of Display DataAnnotation from database instead of hardcoding its value?
Also how can I change the ScaffoldColumn(True/false) based on table values?
Can I do this using T4 template ?
Thanks in advance.
Generally speaking no, the attributes are compiled and become part of the CIL metadata. To investigate this is a good SO thread that goes into some detail on this topic. Is it possible to modify the attribute of a property at runtime?
Personally i think you should be looking at another way to pass the label to the front-end so you can be flexible. eg a Model that contains labels and values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With