I create the following attribute:
public class SpecificDataTypeAttribute : DataTypeAttribute { public SpecificDataType(DataType dataType, string field) : base(dataType) { this.ErrorMessage = string.Format("{0} {1}", field, Messages.SpecificDataTypeAttribute); } }
And use like:
[SpecificDataType(DataType.DateTime, "Initial date")] public DateTime? InitialDate { get; set; }
So the message that is in Messages.SpecificDataTypeAttribute is "is in a incorrect format." . When I entered the wrong date in InitialDate, I got a default error: "The value '12' is not valid for InitialDate." . What for? I set a breakpoint and the code calls the SpecificDataType ctor.
Vinicius ottoni
source share