public IActionResult OnPost() { try { if (ModelState.IsValid) { var repo = new ProfilesRepository(_context); bool saved = repo.SaveProfile(ProfileViewModel); if (saved) { return(RedirectToPage("Index")); } } // Handling model state errors is beyond the scope of the demo, so just throwing an ApplicationException when the ModelState is invalid // and rethrowing it in the catch block. throw new ApplicationException("Invalid model"); } catch (ApplicationException ex) { Debug.Write(ex.Message); throw; } }