C# ASP.NET MVC Foolproof RequiredIf - how to set ErrorMessage to be the value of other (string) property?

4.1k Views Asked by At

That's what I'm looking for:

[RequiredIf("IsNewClient", true, ErrorMessage =*The value of other (string) property*)]

That's would be even better:

[RequiredIf("IsNewClient", true, ErrorMessage =*Calling a function and get the value*)]
1

There are 1 best solutions below

0
Murat Yıldız On

You can use a similar approach like that:

[RequiredIf("GoAbroad == true")]
public string PassportNumber { get; set; }

For more information have a look at ExpressiveAnnotations. Hope this helps...