我有一个声明为的常量:
public static class Constants
{
public static string DATE_FORMAT = "dd-MMM-yyyy";
}
我的一个模型字段上有一个DisplayFormat属性:
[DisplayFormat(DataFormatString = Constants.DATE_FORMAT, ApplyFormatInEditMode = true, NullDisplayText = "Not Yet")]
显示错误:
属性参数必须是常量表达式
但这有效:
[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
当我切换常量的硬编码格式时,它会失败。可以这样做吗?