我已经使用此覆盖来检测枚举并为它们显示自定义编辑器模板。我想对日期/日期时间做同样的事情。
是否可以在同一个代码块中完成?我觉得这应该很容易,但不能完全从它接受的参数中弄清楚。
public class MakeEnumsUseDefaultTemplate : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
{
var mm = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
if (modelType.IsEnum && mm.TemplateHint == null)
{
mm.TemplateHint = "EnumAsSelect";
}
return mm;
}
}