I need to be able to bypass/disable/change a view model's validation when inside other view model.
For example, this is my view model containing other view models:
public class OrderVM
{
public SignMethod SignMethod { get; set; }
public LoginVM LoginVM { get; set; }
public RegisterVM RegisterVM { get; set; }
}
public class LoginVM
{
[Required]
public string Email { get; set; }
// More properties here...
}
public class RegisterVM
{
[Required]
public string Email { get; set; }
// More properties here...
}
And they have validation attributes (on the properties) that I would like to bypass/disable/change or add.
In this example, the view models of LoginVM
and RegisterVM
must contain required properties since it's a standalone view model for the login and register pages.
But, inside the OrderVM
the required validation on LoginVM
or RegisterVM
should only be applied according to the SignMethod
property, if the user has selected SignMethod.Login
then the required validation on LoginVM
should be applied and in RegisterVM
should be disabled, and same for the opposite.
How can I achieve this behavior and represent it properly in the view models?