Hey. I'm trying to redirect to the new controller after creating an account, but for some reason, the code does not work. Here is my code:
[HttpPost] public ActionResult Register(Register model) { if(ModelState.IsValid) { try { Membership.CreateUser(model.Username, model.Password, model.EMail); Roles.AddUserToRole(model.Username, "subscriber"); RedirectToAction("AccountCreated" , "Account"); } catch(Exception ex) { ModelState.AddModelError("" , ex.Message); } } else { ModelState.AddModelError("" , "One or more fields are not completed"); } return View(model); } public ActionResult AccountCreated() { return View(); }
I tried both RedirectToAction("AccountCreated" , "Account"); "); And Redirect("~/Account/AccountCreated") , but both of them do not work. During debugging, I noticed that, when it reaches this part of the code, she misses her.
And I know that the application does not generate an exception, because it creates an account.
What is the problem?
source share