public async Task <IActionResult> OnPostAsync() { // For step-by-step validation to work we need to remove validaton from ModelState for all next steps. if (CurrentSetupStep == SetupStep.Database) { // Removing next step validation. ModelState.Remove("Input.Email"); ModelState.Remove("Input.Password"); ModelState.Remove("Input.PortfolioTitle"); if (ModelState.IsValid) { string connectionString = $"Server={Input.DbServer};Database={Input.Db};User={Input.DbUser};Password={Input.DbPassword};"; (bool, string)result = await _setupService.TestDatabaseConnectionAsync(connectionString); if (!result.Item1) { StatusMessage = "Error: " + result.Item2; } else { _appSettings.Update(opt => opt.ConnectionString = connectionString); CurrentSetupStep = SetupStep.Mailer; return(Page()); } } } else if (CurrentSetupStep == SetupStep.Mailer) { // Removing next step validation. ModelState.Remove("Input.Email"); ModelState.Remove("Input.Password"); ModelState.Remove("Input.PortfolioTitle"); if (ModelState.IsValid) { CurrentSetupStep = SetupStep.Other; return(Page()); } } else if (CurrentSetupStep == SetupStep.Other) { // Removing next step validation. ModelState.Remove("Input.Email"); ModelState.Remove("Input.Password"); if (ModelState.IsValid) { CurrentSetupStep = SetupStep.Account; return(Page()); } } else if (CurrentSetupStep == SetupStep.Account) { if (ModelState.IsValid) { (bool, List <string>)result = await _setupService.CreateDbAndAccountAsync($"Server={Input.DbServer};Database={Input.Db};User={Input.DbUser};Password={Input.DbPassword};", Input.Email, Input.Password); if (!result.Item1) { foreach (string error in result.Item2) { ModelState.AddModelError(string.Empty, error); } return(Page()); } // finish and save everything here _appSettings.Update(opt => { opt.ConnectionString = $"Server={Input.DbServer};Database={Input.Db};User={Input.DbUser};Password={Input.DbPassword};"; opt.PortfolioTitle = Input.PortfolioTitle; opt.SetupFinished = true; }); _mailerOptions.Update(opt => { opt.EmailFrom = Input.MailerEmailFrom; opt.Host = Input.MailerHost; opt.Port = Input.MailerPort; opt.CredentialUserName = Input.MailerCredentialUserName; opt.CredentialPassword = Input.MailerCredentialPassword; }); IsSetupFinished = true; CurrentSetupStep = SetupStep.Finished; return(Page()); } } else { } return(Page()); }