Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamically change data annotation in dynamic data project

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.

like image 564
Praveen VR Avatar asked May 20 '13 07:05

Praveen VR


1 Answers

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.

like image 101
phil soady Avatar answered Oct 19 '22 19:10

phil soady