0

我希望能夠讀取傳遞到自定義驗證屬性的ErrorMessage字符串,以便我可以在其上執行一些string.Format()。但我似乎無法找到它?從自定義驗證屬性中訪問ErrorMessage

因此,例如,我有一個自定義屬性:

[IsDateBeforeFixedDate(4, 0, 0, ErrorMessage = "*The departure date should be between 4 days and 11 months")] 

decalred爲:

public sealed class IsDateBeforeFixedDateAttribute : ValidationAttribute, IClientValidatable 
    { 

    public IsDateBeforeFixedDateAttribute(int days, int months, int years) : base(days, months, years) 
    { 
     //I want to read the ErrorMessage string here! (i.e. "*The departure date should be between 4 days and 11 months") 
    } 
    } 

ErrorMessageString不包含它或ErrorMessage

回答

0

看來,如果我訪問它的IsValid方法它包含正確的字符串,但它不在構造器中