Forwarding page is not working

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?

+4
source share
1 answer

You must return the ActionResult of his actions, so change the line to

 return RedirectToAction("AccountCreated" , "Account"); 

Cm. Example the MSDN Controller.RedirectToAction .

+5
source

All Articles