0

I'm creating a login screen for my MVC3 website. Obviously, the user logs in from this page but if they have forgotten their password they can click a link then Javascript hides the LogOn and then a forgotten appears where they can enter their email address. So I have a LogOnModel which requires the username and password fields to have a value. The ForgotModel requires that the emailAddress field have a value. Then on the page I use a LogOnMaster model that consists of both of these.

public class LogOnMasterModel : MasterViewModel
{
    public LogOnModel LoginViewModel { get; set; }
    public ForgettenModel ForgottenViewModel { get; set; }
} 

The problem is when I click the submit button for LogOn, it wants the email address field to have a value. How can I make it only validate the LoginViewModel on the log in submit button and only validate the ForgottenModel when the forgotten submit button is clicked.

I can share code if need be.

I am open to completely different solutions.

1 Answer 1

2

There are a few methods you can use. The first would involve employing a custom validator that determines if the username/password fields are populated then the email address is not necessary. The second method you might try, since everything is apparently run with JavaScript, is to populate the email address field with some default ignored value ([email protected] or something) that is reset to empty when the Forgot Password link is clicked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.