I want to create an ErrorMessage containing another variable or property value in it. I want to keep it simple. So far this piece of code shows an error for the String.Format parameter. What is the best way to achieve it:
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; }
}
I have already read this question and answer: string.Format in Data Annotation Validation Attributes That's ok, but maybe there is a workaround...