动态改变数据标注在动态数据项目 [英] Dynamically change data annotation in dynamic data project
问题描述
我也接触过之情况,为自定义动态数据的Web应用程序DataAnnotations。这是在之情况:
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;}
而不是硬编码名称=DispName为显示DataAnnotation的,我想取从数据库中的一些价值,适合INT Name属性。这样的:
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;}
有什么办法来显示从数据库显示DataAnnotation的名称属性,而不是硬编码的价值?
Is there any way to show the Name attribute of Display DataAnnotation from database instead of hardcoding its value?
另外我怎么能修改 ScaffoldColumn(TRUE / FALSE)根据表中的值?
Also how can I change the ScaffoldColumn(True/false) based on table values?
我能做到这一点使用T4模板吗?
Can I do this using T4 template ?
先谢谢了。
推荐答案
一般来说没有,属性被编译并成为CIL元数据的一部分。为了研究这是一个很好SO跟帖说进入这个主题的一些细节。 <一href=\"http://stackoverflow.com/questions/1490837/is-it-possible-to-modify-the-attribute-of-a-property-at-runtime\">Is可以修改属性的属性在运行时?
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屋!