6

Is there any way to set dynamically the dataannotations according to some values in database?

My requirement is like this:

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;}

This should be done using t4 template also.

Is there any way to accomplish this?

Regards,

Sujith

Sujith S Nair
  • 738
  • 6
  • 20

1 Answers1

3

Not sure if i get what you mean. To me T4 generation doesnt make much sense in your case but have a look at this Phil Haack approach: http://haacked.com/archive/2011/07/14/model-metadata-and-validation-localization-using-conventions.aspx

In contrast to your request he is modifying data annotations at runtime, using custom ModelMetadataProvider.

Boris Bucha
  • 630
  • 4
  • 6