说,我有一个MVC模型
public class MyModel
{
[Display(Name = "Sophistically-named field", Description = "blah-blah")]
public int SophisticallyNamedField {get;set;}
}
有什么办法可以从注释中获取字段的名称和描述吗?我需要在C#代码中获取它,而不是在Razor中。
答案 0 :(得分:0)
使用Reflection访问给定Attribute的值。您可能需要查看GetCustomAttribute方法,或查看此网站上one个样本的countless。