문제

Error message using Data Annotations but in ErrorMessage I want to pass variable string but when I do that it gives error when project is build.

string errorMessage="Something happened";

[Remote("IsTimeValid", "Account", AdditionalFields = "TaskDate,TodoID", ErrorMessage =errorMessage)]
public string Time{get;set;}

Is there any way to show variable value in ErrorMessages?

도움이 되었습니까?

해결책

You have the ability to do pretty much exactly what you're asking (in your comment).

You set ErrorMessageResourceType to be the type which contains the static property and you set ErrorMessageResourceName to be the name of the property on the class

E.g.

public class Time
{
    [Remote("IsTimeValid", "Account", AdditionalFields = "TaskDate,TodoID", ErrorMessageResourceType = typeof(Time), ErrorMessageResourceName = "InvalidTimeZoneMessage")]
    public string Time{get;set;}

    public static string InvalidTimeZoneMessage
    {
        get
        {
            return "You have the wrong timezone";
        }
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top