別の変数またはプロパティ値を含む ErrorMessage を作成したいと考えています。シンプルに保ちたい。これまでのところ、このコードは String.Format パラメーターのエラーを示しています。それを達成するための最良の方法は何ですか:
public class MyClass
{
[RequiredIf("IsRequired", true, ErrorMessage=String.Format("The 'something' ({0}) is required because of: {1}", Something, CustomExplanation)]
public string Something { get; set; }
[Required]
public bool IsRequired { get; set; }
[Required]
[StringLength(200, MinimumLength=20)]
public string CustomExplanation { get; set; }
}
私はすでにこの質問と回答を読んでいます: string.Format in Data Annotation Validation Attributes 大丈夫ですが、回避策があるかもしれません...