在动态数据项目中动态更改数据注释 [英] Dynamically change data annotation in dynamic data project
问题描述
我已经遇到了在Dynamic Data Web应用程序中自定义DataAnnotations的风景。这是scenerio:
[Display(Name =DispName)]
public string DName {get; set ;}
而不是为Display DataAnnotation硬编码Name =DispName,我想从DataBase并适应Name属性。如:
[Display(Name = SomeValueFromDB)]
public string DName {get; set;}
有没有办法从数据库中显示Display DataAnnotation的Name属性,而不是硬编码它的值?
另外如何根据表格值更改 ScaffoldColumn(True / false)?
我可以使用T4模板吗?
提前感谢
解决方案一般来说,被编译并成为CIL元数据的一部分。调查这是一个很好的线程,详细介绍这个主题。 是否可以修改属性一个属性在运行时?
个人我认为你应该看另一种方式将标签传递到前端,所以你可以灵活。例如包含标签和值的模型。
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.
这篇关于在动态数据项目中动态更改数据注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!